3
голосов
5ответов
784 просмотров

Most efficient way to add new keys or append to old keys in a dictionary during iteration in Python?

Here's a common situation when compiling data in dictionaries from different sources: Say you have a dictionary that stores lists of things, such as things I like: likes = { 'colors': ['blue','red','purple'], 'foods': ['apples', 'oranges'] } and a second dictionary with some related ...

43
голосов
7ответов
29606 просмотров

Design patterns for converting recursive algorithms to iterative ones

Are there any general heuristics, tips, tricks, or common design paradigms that can be employed to convert a recursive algorithm to an iterative one? I know it can be done, I'm wondering if there are practices worth keeping in mind when doing so.

2
голосов
4ответов
16169 просмотров

Java How to find a value in a linked list iteratively and recursively

I have a method that has a reference to a linked list and a int value. So, this method would count and return how often the value happens in the linked list. So, I decided to make a class, public class ListNode{ public ListNode (int v, ListNode n) {value = v; next = n;) public int value; pub...

4
голосов
7ответов
3176 просмотров

Can you remove an item from a List<> whilst iterating through it in C#

Can you remove an item from a List<> whilst iterating through it? Will this work, or is there a better way to do it? My code: foreach (var bullet in bullets) { if (bullet.Offscreen()) { bullets.Remove(bullet); } } -edit- Sorry guys, this is for a silverlight game. ...

0
голосов
7ответов
402 просмотров

jQuery iterative Timer

I want to create a jQuery iterative timer. For this I wrote the following script: $(document).ready(function(){ var t; function x() { alert('x') t = setTimeout("x()",1000); } x(); }); First time the function x() called successfully. But from the next functio...

1
голосов
3ответов
1440 просмотров

Iterating over nested lists with a Next() function, without a generator

Whilst I'd love to solve this problem in python, I'm stuck in Delphi for this one. I have nested lists (actually objects with nested lists as properties, but nevermind), and I want to iterate over them in a generator fashion. That is, I want to write a Next function, which gives me the next item ...

0
голосов
1ответов
333 просмотров

Iterating 1 row at a time with massive amounts of links/joins

Ok, basically what is needed is a way to have row numbers while using a lot of joins and having where clauses using these rownumbers. such as something like select ADDRESS.ADDRESS FROM ADDRESS INNER JOIN WORKHISTORY ON WORKHISTORY.ADDRESSRID=ADDRESS.ADDRESSRID INNER JOIN PERSON ON PERSON.PERSO...

0
голосов
1ответов
365 просмотров

Using Embedded Dictionary for iterative character replacement

I'm trying to understand an iterative function that that takes a string "12345" and returns all the possible misspellings based upon a dictionary of keys close to each character in the string. outerDic = {} Dict1 = {'1':'2','2':'q'} outerDic['1'] = Dict1 Dict1 = {'1':'1','2':'q','3':'w','4':'3'}...

3
голосов
2ответов
532 просмотров

Is iterator.remove() is ROBUST in all cases in java?

As in C++ iterator.remove() is not 100% safe or robust does java guarantees 100% robustness with iterator.remove()?

3
голосов
1ответов
3962 просмотров

Iterative version of Binary Tree Search

Basic Tree-search algorithm for searching a node (with value k) in a binary search tree. 'x' denotes the node of the binary search tree. TREE-SEARCH (x, k) if x= NIL or k = key[x] then return x if k < key[x] then return TREE-SEARCH(left[x], k) else return TREE-SEARCH(right[x], k...

9
голосов
4ответов
2194 просмотров

How to treat the first line of a file differently in Python?

I often need to process large text files containing headers in the first line. The headers are often treated differently to the body of the file, or my processing of the body is dependent on the headers. Either way I need to treat the first line as a special case. I could use simple line iteratio...

0
голосов
3ответов
12244 просмотров

Non-recursive post order traversal

I saw the following post order traversal algorithm in some website... it seems to be correct. I just want to verify that this algorithm works correctly — is this algorithm correct for post order traversal without recursion? void postOrderTraversal(Tree *root) { node * previous = null; n...

1
голосов
5ответов
6594 просмотров

Alternatives to javascript function-based iteration (e.g. jQuery.each())

I've been watching Google Tech Talks' Speed Up Your Javascript and in talking about loops, the speaker mentions to stay away from function-based iterations such as jQuery.each() (among others, at about 24:05 in the video). He briefly explains why to avoid them which makes sense, but admittedly I ...

1
голосов
4ответов
1274 просмотров

LaTeX: How do I know to stop building (programatically)?

I'm trying to build a continuous builder for my latex document, which calls latex and bibtex the appropriate number of times. It checks the myfile.fls file for all the inputs, so it seems I know what all the inputs are. But how can I tell when to stop iterating? It is enough that none of the inp...

0
голосов
3ответов
734 просмотров

Need help converting iterative pattern into formula

var = 8 itr 1: var == 8 (8 * 1) itr 2: var == 24 (8 * 3) itr 3: var == 48 (8 * 6) itr 4: var == 80 (8 * 10) itr 5: var == 120 (8 * 15) Pattern: (var * (last multiplier + current iteration)) Basically I want to get the result of formula(itr) without having to iterate up to itr.

2
голосов
1ответов
1226 просмотров

Using JavaScript/jQuery to generate fixtures

I'm putting together a tool for a colleague which helps to create a nice fixture list. I got about 2/3 through the tool, collecting various data ... and then I hit a brick wall. It's less of a JavaScript problem and more of a maths/processing brainblock. Lets say I have 4 teams, and they all nee...

0
голосов
3ответов
786 просмотров

How to get index number inside $.click() of jQuery?

$("span.ws_label").click(function() { }) By selector "span.ws_label" there are 5 elements selected, when one of them is clicked, how to know which one actually? EDIT I must get the index or its id,$(this) is no use to me.

8
голосов
3ответов
10152 просмотров

Manually iterating a line of a file | bash

I could do this in any other language, but with Bash I've looked far and wide and could not find the answer. I need to manually increase $line in a script. Example: for line in `cat file` do foo() foo_loop(condition) { do_something_to_line($line) } done If you notice, every time the ...

2
голосов
1ответов
1063 просмотров

how to do a iterative rollup in sql

Hi I want to do a rolling sum (of valx) based on previous row value of rolling sum(valy) and the current row value of valx valy=previousrow_valy + valx animal valx valy cat 1 1 cat 3 4 cat 2 6 dog 4 4 dog 6 10 dog 7 17 dog 8 25

2
голосов
2ответов
4178 просмотров

Set a default iteration path for a work item type on TFS

I try to tune my Team Foundation 2005 work items. We have 5 iterations paths in the "Bug" work item type. I would like it to default to a specific value, for example Iterations.Iteration2 I tried to add a DEFAULT rule in the work item type editor but couldn't set the iteration path. How can I d...

0
голосов
3ответов
686 просмотров

JQuery checkbox iteration in ASP.Net C#

I was given the code below to disable a button on an ASP.Net page if none of the checkboxes are checked, and to enable it if any checkboxes get checked. It disables the button fine when the page loads and no boxes are checked, but never hits the $('.cb').change(setButton) code to enable the butt...

1
голосов
1ответов
1764 просмотров

JQuery checkbox iteration in ASP.Net C#

I'm trying to iterate over checkboxes in an ASP.Net web page, and if any of the checkboxes are checked, then I want to enable the button on the page, but if none are checked, I want to disable the button. I'm working on the sample code below to enable the button, but it isn't working correctly. ...

3
голосов
4ответов
10312 просмотров

Jquery Onclick not happening second time

I'm a bit confused as to why this isn't working; I assume that because I'm adding the class and its not being added back into the collection I'm not sure. Here it is on a jsbin http://jsbin.com/ayije although code is below also. Either way I can only get the action to happen on an element once....

0
голосов
1ответов
1026 просмотров

Basic tree in Python with a Django QuerySet

Here's where I'm exposed as the fraud of a programmer I am. I've never created a data tree. Basically, I have a table with four fields: A, B, C, and D. I need to create a tree of unordered lists based on these fields. Ultimately, it would look something like this: A1 B1 C1 D1 D2 C2 ...

31
голосов
9ответов
26240 просмотров

Iteration over list slices

I want an algorithm to iterate over list slices. Slices size is set outside the function and can differ. In my mind it is something like: for list_of_x_items in fatherList: foo(list_of_x_items) Is there a way to properly define list_of_x_items or some other way of doing this using python 2.5...

4
голосов
6ответов
13504 просмотров

How can I find all permutations of a string without using recursion?

Can someone help me with this: This is a program to find all the permutations of a string of any length. Need a non-recursive form of the same. ( a C language implementation is preferred) using namespace std; string swtch(string topermute, int x, int y) { string newstring = topermute; newst...

0
голосов
2ответов
2641 просмотров

Struts forEach tag not iterating through ArrayList

I have some code! The code looks like this: <c:forEach var="element" items="%{serviceList.getServices()}"> <p>Hello!</p> </c:forEach> "serviceList" is a bean, with a method on it called getServices(). getServices() returns an ArrayList, so I naturally assumed th...

0
голосов
5ответов
2207 просмотров

JQuery if statement

I've written some JQuery code to iterate over some checkboxes on an ASP.Net web page, and am seeing 2 very strange problems with the if statement embedded in the $.each function. The code is selecting my checkboxes just fine, and as the code iterates through the $.each function I can clearly see...

1
голосов
2ответов
1658 просмотров

Omaha Hi Hand Evaluator

Currently I'm trying to port Keith Rule's Texas Holdem Hand Evaluator to Omaha Hi: Texas Holdem Evaluator and Analysis More Analysis Part1 More Analysis Part 2 After thinking more about the algorithm, I found a solution which gives me the right percentages for the hands and everything is fi...

1
голосов
2ответов
5690 просмотров

JQuery .each() callback function doesn't run on each iteration/loop

Here's what should happen. 1. Get the rel attribute of the clicked link 2. For every div with class 'entry': (i)Get its 'left' position (ii) Calculate its outer height (iii)Loop through all instances of 'a.tag_filter'. If it finds the same string in the 'rel' as the one oringinally cl...