iterate

Removing Item From List - during iteration - what's wrong with this idiom ?

As an experiment, I did this: letters=['a','b','c','d','e','f','g','h','i','j','k','l'] for i in letters: letters.remove(i) print letters The last print shows that not all items were removed ? (every other was). IDLE 2.6.2 >>> ================================ RESTART ================================ >>> ['b', 'd', 'f', 'h'...

Iterating through boost ptr_vector

Hello, I have a ptr_vector list of my own objects. Something like this: boost::ptr_vector<SomeClass> *list; list->push_back(new SomeClass()>; ... BOOST_FOREACH(SomeClass *tempObj, list) // [x] { tempObj->... } >‘boost::ptr_vector<SomeClass>*’ is not a class, struct, or union type ...

How can I iterate over only the first variable of a tuple

In python, when you have a list of tuples, you can iterate over them. For example when you have 3d points then: for x,y,z in points: pass # do something with x y or z What if you only want to use the first variable, or the first and the third. Is there any skipping symbol in python? ...

Get the most repeated element in a sequence with XQuery

Hello, I've got a sequence of values. They can all be equal... or not. So with XQuery I want to get the most frequent item in the sequence. let $counter := 0, $index1 := 0 for $value in $sequence if (count(index-of($value, $sequence))) then { $counter := count(index-of($value, $sequence)) $index1 := index-of($value) } else {} ...

C++, console Application, reading files from directory

I have a directory and I want to read all the text files in it using C++ and having windows OS also using console application I don't know the files' names or their number thanks in advance ...

Django iterating problem - calculating a sum

i;m trying to iterate through some values, and calculate a rank. i have a calculate_rank function where i calculate a sum of values. The problem is at the second function. I want that a user's rank to be the sum of all the user that in a follow relation with him. I am doing an iteration in the second function here where i try to add the...

Iterating over an array

Possible Duplicate: automatically get loop index in foreach loop in perl I'd like to iterate over an array, but I need to keep track of the index. This code doesn't list the indexes as I'd expect - how can I fix it? $arr = [0,0,0,0]; foreach $i (0 .. scalar @$arr) { print $i; } ...

Iterating circular way

I need iterate through a List but circular way. I need too add new elements to the list and iterate over all elements (olds and news elements), How I do it? Is there any data structure for them? ...

Multiple Submit in one Form using struts 1.3

Hello! It happens that in my app I throw a lot of data to one logic:iterate, but they need more data, data that is dependent on each row of the iterate. So I thought to put one submit button in each row of the iterate (or maybe a link), so I can redirect the app to the next page. Problem is, the actionForm always submit the first row of...

Find pixel where max width and max height of a coloured area intersect using GetPixel()

I'm using GetPixel to get the colour of each pixel of an image. The images contain different plain-coloured irregular shapes, and I'd like to find the point (or pixel) where the maximum width matches the maximum height (see figure below). (disregard the border) I'm using this to iterate through the captured bitmap: for (int ...

Is it safe to delete an object property while iterating over them?

When iterating over an object's properties, is it safe to delete them while in a for-in loop? For example: for (var key in obj) { if (!obj.hasOwnProperty(key)) continue; if (shouldDelete(obj[key])) { delete obj[key]; } } In many other languages iterating over an array or dictionary and deleting inside that is uns...

jQuery sum child table row cells to parent row

I have an HTML table that is similar to this simplified example: <table> <tbody> <tr><th>Player</th><th>Score</th></tr> <tr><td>Jack</td><td>7</td></tr> <tr><td class="parent">Green Team</td><td></td></tr> <tr><td class="child">Mark</td><td>11</td></tr> <tr><td class="child">Tom</td><td>5</td></tr> <tr><td>Stev...

Batch File: Iterate Over Files Modified Since a Given Date

I want to create a batch file that executes a command (delete the file, for a simple example, though my command is custom/different) on each file matching a wildcard (say *.jpg) that was modified since some date (such as 1-1-2010 or later). The date can either be hardcoded in the batch file or passed as a command line param. Pseudocode...

C# - Iterating over and invoking class members

I'm trying to iterate over the members of a static class and invoke all of the members that are fields. I get a MissingFieldException on the line where I attempt to invoke the member. Something like this: "Field 'NamespaceStuff.MyClass+MyStaticClass.A' not found." public class MyClass { public MyClass() { Type type = typeo...

Can StringTemplate iterate through 'values' in a String?

I have a String made up of several Strings seperated by commas. Using StringTemplate, is there an easy way to write a seperate line for each 'value' in this outer String? For example, I have: String layers = "ADM,NAV"; and I want to output: ADM,Y, NAV,Y, I suspect the template would look (if it's possible) something like this: $...

PHP: count how many times a number appears in an array?

I'm running a loop basically that will make an array that contains a million numbers between 1 and 10, how do I iterate through it and count how many of each there are? Like: 1 - 201491 times 2 - 23091 times ...

In Ibatis, how does one write a nested Iterate tag to loop through a two-dimensional array?

Hi all, I was troubleshooting the following code and was unable to find an answer, so I figured I would document my solution. The problem was: <iterate property="twoDimArray" prepend="and (" close=")" conjunction="or"> <iterate property="twoDimArray[]" open="(" close=")" conjunction="and"> $twoDimArray[][].columnName$ = #twoDimArray[]...

Django / Python, using iteritems() to update database gives strange error: "dictionary update sequence element #0 has length 4; 2 is required"

I'm trying to do a Django database save from a form where I don't have to manually specify the fieldnames (as I do in the 2nd code block), the way I am trying to do this is as below (1st code block) as I got the tip from another S.O. post. However, when I try this I get the error "dictionary update sequence element #0 has length 4; 2 is ...

Why do you have to call .iteritems() when iterating over a dictionary in python?

Why do you have to call iteritems() to iterate over key, value pairs in a dictionary? ie dic = {'one':'1', 'two':'2'} for k, v in dic.iteritems(): print k, v Why isn't that the default behavior of iterating over a dictionary for k, v in dic: print k, v ...

How would you (re)implement iterate in Haskell ?

iterate :: (a -> a) -> a -> [a] (As you probably know) iterate is a function that takes a function and starting value. Then it applies the function to the starting value, then it applies the same function to the last result, and so on. Prelude> take 5 $ iterate (^2) 2 [2,4,16,256,65536] Prelude> The result is an infinite list. (th...