range

Python list initialization using multiple range statements

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 02:41:24
I want one long list, say [1,2,3,4,5,15,16,17,18,19] as an example. To initialize this, I try typing: new_list = [range(1,6),range(15,20)] However this doesn't do what I want, returning: [[1, 2, 3, 4, 5], [15, 16, 17, 18, 19]] When I do: len(new_list) It returns 2, instead of the 10 elements I wanted (since it made 2 lists inside the list). Obviously in this example I could just type out what I want, but I'm trying to do this for some odd iterated lists that go like: new_list = [range(101,6284),8001,8003,8010,range(10000,12322)] Desiring a 1-D list instead of a list of lists (or whatever it's

Disable track on HTML5 range input

半世苍凉 提交于 2019-12-01 01:44:47
I'm trying to find a way to prevent the user from clicking into the "track" portion of an HTML5 range input. Essentially, I only want the user to be able to use the "handle" to change the range value. Is this even possible? It's possible through pointer-events at least on chrome. input[type=range] { pointer-events: none; } input[type=range]::-webkit-slider-thumb { pointer-events:auto; } This will disable clicking on the track and enable clicking only on slider thumbs. Adding disabled should work. <input id="rangeindicator" disabled type="range" name="points" min="1" max="10"> and then you can

Ruby 'Range.last' does not give the last value. Why?

拈花ヽ惹草 提交于 2019-12-01 00:27:31
问题 When using the triple dot notation in a ruby Range object, I get this: (0...5).each{|n| p n} 0 1 2 3 4 When I use the 'last' method I get: (0...5).last => 5 I would have expected 4 Is this is a bug? Or is there something I don't understand about the the concept of a Range object? 回答1: This is by design. The Ruby 2.0 documentation is more specific: Note that with no arguments last will return the object that defines the end of the range even if exclude_end? is true . (10..20).last #=> 20 (10..

Is there an elegant way to exclude the first value of a range?

天大地大妈咪最大 提交于 2019-11-30 23:31:19
问题 Let's say I have a range from 0 to 10: range = 0...10 Three dots mean, that the last value (10) is excluded: range.include? 10 => false Now, is there a similar and elegant way to exclude the first value? For the above example, this would mean to include all values that are bigger ( > , not >= ) than 0 and smaller than 10. 回答1: No. ((0+1)..10) 回答2: I have two suggestions for you, they're not very ideal but they're the best I can think of. First you can define a new method on the Range class

How to select random values from a given range

感情迁移 提交于 2019-11-30 22:59:22
I'm trying to create an android application which will generate random series of values (integer numbers in this case) in a given range (but NOT equal between them) and display them in a simple TextView Let's say we have the range R = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] Each time I press the button "Generate" I want to randomly generate 5 different results Example for each "Generate": 4, 9, 2, 12, 10 5, 1, 6, 8, 13 10, 4, 6, 8, 2 etc... EDIT (works now) Thanks for all the help! public class random extends Activity { static final Integer[] data = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }

In Bash, how to convert number list into ranges of numbers?

点点圈 提交于 2019-11-30 20:34:19
Currently I have a sorted output of numbers from a command: 18,19,62,161,162,163,165 I would like to condense these number lists into a list of single numbers or ranges of numbers 18-19,62,161-163,165 I thought about trying to sort through the array in bash and read the next number to see if it is +1... I have a PHP function that does essentially the same thing, but I'm having trouble transposing it to Bash: foreach ($missing as $key => $tag) { $next = $missing[$key+1]; if (!isset($first)) { $first = $tag; } if($next != $tag + 1) { if($first == $tag) { echo '<tr><td>'.$tag.'</td></tr>'; } else

jquery slider, time picker and reserved times..

痞子三分冷 提交于 2019-11-30 20:08:24
I am using a jquery slider to pick a start and end time That is fine, but I need to add restrictions to it. Basically, I've got a window of availability that I need to chip away at. So in my example: http://madeeasyfor.me/stackoverflow/time_pick_test_1.html (I've commented the validation function so you can see the slider, the code has absolute paths to all scripts so feel free to get a view source dump for local use) I've got a 24 clock. With a dynamically generated PHP script, I want to add various booked times.. so when the user tries to select a pre booked time, they'll get an error (pop

Add element before/after text selection

流过昼夜 提交于 2019-11-30 19:38:29
I'm looking for function which allows me to build some element before or after selected text. Something similar like this one javascript replace selection all browsers but for adding some content before or after selection instead of replacing it, like after() and before() jQuery methods. Should I use some DOM selection method, if yes which one? Or does exist something easier to carry it out? Here's a pair of functions to do this. Live example: http://jsfiddle.net/hjfVw/ Code: var insertHtmlBeforeSelection, insertHtmlAfterSelection; (function() { function createInserter(isBefore) { return

(Python) List index out of range - iteration [duplicate]

£可爱£侵袭症+ 提交于 2019-11-30 19:08:36
问题 This question already has answers here : python : list index out of range error (11 answers) How to remove items from a list while iterating? (29 answers) Closed 2 years ago . for i in range(len(lst)): if lst[i][0]==1 or lst[i][1]==1: lst.remove(lst[i]) return lst This gives "IndexError: list index out of range" Why is this happening? 回答1: You're modifying the list you're iterating over. If you do that, the size of the list shrinks, so eventually lst[i] will point beyond the list's boundaries

Data Structure for Storing Ranges

你。 提交于 2019-11-30 18:57:11
I am wondering if anyone knows of a data structure which would efficiently handle the following situation: The data structure should store several, possibly overlapping, variable length ranges on some continuous timescale. For example, you might add the ranges a:[0,3], b:[4,7], c:[0,9] . Insertion time does not need to be particularly efficient. Retrievals would take a range as a parameter, and return all the ranges in the set that overlap with the range, for example: Get(1,2) would return a and c. Get(6,7) would return b and c. Get(2,6) would return all three. Retrievals need to be as