range

Changing the value of range during iteration in Python

痴心易碎 提交于 2019-12-02 11:33:23
>>> k = 8 >>> for i in range(k): print i k -= 3 print k Above the is the code which prints numbers from 0-7 if I use just print i in the for loop. I want to understand the above code how it is working, and is there any way we can update the value of variable used in range(variable) so it iterates differently. Also why it always iterates up to the initial k value, why the value doesn't updated. I know it's a silly question, but all ideas and comments are welcome. You can't change the range after it's been generated. In Python 2, range(k) will make a list of integers from 0 to k, like this: [0,

javascript contentEditable - wrap cross-tag selections

主宰稳场 提交于 2019-12-02 10:36:19
问题 I'm experimenting a bit with contentEditable and encountered this issue: I have the following js snippet var range = document.getSelection().getRangeAt(0); var newNode = document.createElement("span"); newNode.className = "customStyle"; range.surroundContents(newNode); and this HTML fragment: <ul> <li>the <b>only entry</b> of the list</li> </ul> <p>Some text here in paragraph</p> The js code allows to wrap the current selection with a <span> tag. It works perfectly when the selection includes

Modulus of a really really long number (fmod)

旧巷老猫 提交于 2019-12-02 10:35:59
问题 I want to find the number of zeroes in a factorial using Cpp. The problem is when I use really big numbers. #include <stdio.h> #include <math.h> long zeroesInFact(long n) { long double fact=1; long double denominator=10.00; long double zero=0.0000; long z=0; printf("Strating loop with n %ld\n",n); for(int i=2;i<=n;i++) { fact=fact*i; printf("Looping with fact %LF\n",fact); } printf("Fmod %lf %d\n",fmod(fact,denominator),(fmod(fact,denominator)==zero)); while(fmod(fact,denominator)==zero) {

setStart and setEnd throwing error when trying to programmatically select text in UIWebView

跟風遠走 提交于 2019-12-02 10:03:53
Here is some HTML that I am working with in my UIWebView: <div id = "1"> <span style = "background-color:red"> <a href = "10&20"> This is a link </a> </span> </div> Once the link is tapped, I want to programmatically select the link text in the UIWebView (so "This is a link" would now be highlighted with the blue iOS text selection tool). This is why I am sending some range information in the href of the a tag. This is the call I am using to try and make this programmatic selection: //set content editable true [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@

Run-time error '1004' : Method 'Range' of object'_Global' failed; SIMPLE COPY AND PASTE

妖精的绣舞 提交于 2019-12-02 09:06:34
I'm just trying to do a simple cut and paste to shift ranges in F:G to an unoccupied cell in D but I keep getting that error message. My codes are in the Modules and I don't know what I'm doing wrong! Completely new to VBA. Highlighted portion: Range("F" & RowNum & ":G" & RowNum).Select Sub MoveCells(RowNum as Integer) Range(“F” & RowNum & ":G" & RowNum).Select Selection.Cut Range(“D” & RowNum).Select ActiveSheet.Paste End Sub Range(“F” & RowNum & ":G" & RowNum).Select ^ ^ ^ ^ | | | | Chr(147) Chr(34) The 'quotation marks' around F are character 147. To denote a string value you have to use

Python Recursion: Range

回眸只為那壹抹淺笑 提交于 2019-12-02 09:01:59
I need to define a function called rec_range(n) which takes a natural number and returns a TUPLE of numbers up to the number n. i.e. rec_range(5) returns (0,1,2,3,4) rec_range(1) returns (0,) This is what I have come up with so far. def rec_range(n): """takes a natural number n and returns a tuple of numbers starting with 0 and ending before n Natural Number -> Tuple of Numbers""" if n == 0: return 0 else: return (rec_range(n-1), ) This works for rec_range(1). ***Restrictions are: must be defined recursively, cannot use lists, loops or use the existing range() function I would write it as

Sorting range in ascending numerical order containing strings by vba excel

倖福魔咒の 提交于 2019-12-02 08:56:46
问题 i have a range containing the following strings: step_1, step_10, step_3, step_2 using the following code input_sh.Activate With ActiveSheet .Range("H2:H20").Select .Sort.SortFields.Clear .Sort.SortFields.Add Key:=Range("H2"), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers 'xlSortNormal With .Sort .SetRange Range("H2:H20") .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With step_10, step_1, step_2, step_3 but i

How to check if two ranges value is equal

大憨熊 提交于 2019-12-02 08:33:26
I want to merge cells in columns, if there is the same value in whole row. Eg. If A1:G1 range is the same as A2:G2 I want to merge A1:A2 cells, B1:B2 to G1:G2. With my code below I get run time error 13: type mismatch. I'm assuming, that problem is with checking equality of two ranges. Dim i As Long, j As Long, row as Long row = Cells(Rows.Count, 6).End(xlUp).row For i = row To 7 Step -1 If Range(Cells(i, 7), Cells(i, 24)).Value = Range(Cells(i - 1, 7), Cells(i - 1, 24)).Value Then For j = 7 To 24 Step 1 Range(Cells(i, j), Cells(i - 1, j)).Merge Next j End If Next i The question is, how to

VBA copy & paste with dynamic range

旧巷老猫 提交于 2019-12-02 08:22:12
I'm new with VBA and I'm stuck somewhere. I have to copy last row of column A till column H and paste it untill the last row of column I. Last rows of columnns will be always change. e.g; my data is in A2:H2 and I5 is the last cell with data. My code should be copy A2:H2 and paste it A3:H5. And second time I run the macro (after I add new data to respective columns) it should be copy A6:H6 and paste it untill the last row of column I. I wrote two codes which were not fulfill my needs. first code is ; Sub OrderList1() Range("a65536").End(xlUp).Resize(1, 8).Copy _ (Cells(Cells(Rows.Count, 9).End

How can I specify the range of a random number?

江枫思渺然 提交于 2019-12-02 07:47:40
I have binary search tree code that inserts numbers randomly. I can modify size each time, but I want to modify the range of numbers, for example: I want the random number be just one digit or just 2 digits. How can I do that? public static void main( String[ ] args ) { BinarySearchTree bst = new BinarySearchTree( ); Random random = new Random( System.currentTimeMillis() ); int[] randoms = new int[1000]; Random randGen = new Random(); for(int i = 0; i < randoms.length; i++) { bst.insert( random.nextInt( randoms.length ) ); } System.out.println( "\n sorted :" ); bst.inorderTraversal( ); bst