range

Skip over a value in the range function in python

怎甘沉沦 提交于 2019-11-27 01:14:11
问题 What is the pythonic way of looping through a range of numbers and skipping over one value? For example, the range is from 0 to 100 and I would like to skip 50. Edit: Here's the code that I'm using for i in range(0, len(list)): x= listRow(list, i) for j in range (#0 to len(list) not including x#) ... 回答1: You can use any of these: # Create a range that does not contain 50 for i in [x for x in xrange(100) if x != 50]: print i # Create 2 ranges [0,49] and [51, 100] (Python 2) for i in range(50)

Concatenating two range function results

落花浮王杯 提交于 2019-11-27 01:00:31
Does range function allows concatenation ? Like i want to make a range(30) & concatenate it with range(2000, 5002) . So my concatenated range will be 0, 1, 2, ... 29, 2000, 2001, ... 5001 Code like this does not work on my latest python (ver: 3.3.0) range(30) + range(2000, 5002) You can use itertools.chain for this: from itertools import chain concatenated = chain(range(30), range(2000, 5002)) for i in concatenated: ... It works for arbitrary iterables. Note that there's a difference in behavior of range() between Python 2 and 3 that you should know about: in Python 2 range returns a list, and

onChange event for HTML5 range

被刻印的时光 ゝ 提交于 2019-11-27 00:49:30
问题 Currently the onChange event on my range inputs is firing at each step. Is there a way to stop this event from firing until the user has let go of the slider? I'm using the range to create a search query. I want to be able to run the search every time the form is changed but issuing a search request at each step of the slider's movement is too much. Here's the code as it stands: HTML: <div id="page"> <p>Currently viewing page <span>1</span>.</p> <input class="slider" type="range" min="1" max=

Android Seekbar with two thumbs

坚强是说给别人听的谎言 提交于 2019-11-27 00:39:55
Variations of this question can be found all over the internet but not an answer. I want a seekbar with two-thumb range selection. I'm willing to program this myself but I lack experience with Android. Could someone give me some pointers on where to start. I mean, I know I will have to extend something (ProgressBar probably), but how should I go about to do that? Do I really have to recreate all the functionality of a standard seekbar, or is there an easier way? Complete solutions are also welcome of course ;) Stephan Tittel I too was looking for this, to no avail. So I made a new widget, feel

How to check an IP address is within a range of two IPs in PHP?

自古美人都是妖i 提交于 2019-11-27 00:35:36
I have an IP address and I'm given two other IP addresses which together creates an IP range. I want to check if the first IP address is within this range. How can i find that out in PHP? oezi With ip2long() it's easy to convert your addresses to numbers. After this, you just have to check if the number is in range: if ($ip <= $high_ip && $low_ip <= $ip) { echo "in range"; } John Conde This website offers a great guide and code to do this (which was the first result of a Google search for this question): <?php /* * ip_in_range.php - Function to determine if an IP is located in a * specific

What's a good, generic algorithm for collapsing a set of potentially-overlapping ranges?

空扰寡人 提交于 2019-11-27 00:34:53
问题 I have a method that gets a number of objects of this class class Range<T> { public T Start; public T End; } In my case T is DateTime , but lets use int for simplicity. I would like a method that collapses those ranges into ones that cover the same "area" but that do not overlap. So if I had the following ranges 1 to 5 3 to 9 11 to 15 12 to 14 13 to 20 The method should give me 1 to 9 11 to 20 Guess it would be called a union? I imagine the method signature could look something like this:

Fast Algorithm to Quickly Find the Range a Number Belongs to in a Set of Ranges?

允我心安 提交于 2019-11-27 00:26:39
The Scenario I have several number ranges. Those ranges are not overlapping - as they are not overlapping, the logical consequence is that no number can be part of more than one range at any time. Each range is continuously (there are no holes within a single range, so a range 8 to 16 will really contain all numbers between 8 and 16), but there can be holes between two ranges (e.g. range starts at 64 and goes to 128, next range starts at 256 and goes to 384), so some numbers may not belong to any range at all (numbers 129 to 255 would not belong to any range in this example). The Problem I'm

HTML5 input type range show range value

一笑奈何 提交于 2019-11-26 23:31:20
I am making a website where I want to use range slider(I know it only supports webkit browsers). I have integrated it fully and works fine. But I would like to use a textbox to show the current slide value. I mean if initially the slider is at value 5, so in text box it should show as 5, when I slide the value in text box should change. Can I do this using only CSS or html. I want to avoid JQuery. Is it possible? ejlepoud This uses javascript, not jquery directly. It might help get you started. function updateTextInput(val) { document.getElementById('textInput').value=val; } <input type="range

Continuous integer runs

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 23:26:38
问题 I have some data in a list that I need to look for continuous runs of integers (My brain think rle but don't know how to use it here). It's easier to look at the data set and explain what I'm after. Here's the data view: $greg [1] 7 8 9 10 11 20 21 22 23 24 30 31 32 33 49 $researcher [1] 42 43 44 45 46 47 48 $sally [1] 25 26 27 28 29 37 38 39 40 41 $sam [1] 1 2 3 4 5 6 16 17 18 19 34 35 36 $teacher [1] 12 13 14 15 Desired output: $greg [1] 7:11, 20:24, 30:33, 49 $researcher [1] 42:48 $sally

VBA: Selecting range by variables

非 Y 不嫁゛ 提交于 2019-11-26 22:48:47
问题 I want to select the formatted range of an Excel sheet. To define the last and first row I use the following functions: lastColumn = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.Count lastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row In the next step I want to select this area: Formula should look like this: Range(cells(1, 1), cells(lastRow, lastColumn).Select However, this is not working. Maybe somebody has an idea what is wrong with it. Thanks a