iteration

Bin Tree Post Order Traversal, No recursion, no node flag

Is there another way to do this? Just spent 2 hours trying to figure it out. I have a solution (see DumpPostOrder below) however, is there is a better or more efficient method? It feels like there may be. Rules are - no recursion, and the nodes cannot have a visited flag. Ie, you can only use left + right members. My approach was to de...

Pythonic way to iterate over sequence, 4 items at a time

Possible Duplicate: What is the most pythonic way to iterate over a list in chunks? I am reading in some PNG data, which has 4 channels per pixel. I would like to iterate over the data 1 pixel at a time (meaning every 4 elements = 1 pixel, rgba). red_channel = 0 while red_channel < len(raw_png_data): green_channel, blue_...

One UIButton at a time

Hello Guys, Here is some code I have been playing with; for some reason I cannot get it to create a single button at a time. For example you have ; for(i = 1; i <=12; i++) should mean that for each time an external button is pressed a new one is created until 12 buttons have been created. Then there should be a i = 12;break somewhere....

How do you iterate backward over circular buffer without a conditional?

Iterating forward through a circular buffer without using a conditional is easy with the remainder operator... iterator = (iterator + 1) % buffer_size; I can't for the life of me figure out the reverse operation, iterating backward. ...

How to iterate over a column vector in Matlab?

I have a column vector list which I would like to iterate like this: for elm in list //do something with elm How? ...

How to iterate a dict of dynamic "depths" in python?

I have a dict data structure with various "depths". By "depths" I mean for example: When depth is 1, dict will be like: {'str_key1':int_value1, 'str_key2:int_value2} When depth is 2, dict will be like: {'str_key1': {'str_key1_1':int_value1_1, 'str_key1_2':int_value1_2}, 'str_key2': {'str_key2_1':int_value2_1, '...

How to loop backwards in python?

I'm talking about doing something like: for(i=n; i>=1; --i) { //do something with i } I can think of some ways to do so in python (creating a list of range(1,n+1) and reverse it, using while and --i, ...) but I wondered if there's a more elegant way to do it. Is there? EDIT: Some suggested I use xrange() instead of range() since r...

Is there a way to iterate a specified number of times without introducing an unnecessary variable?

If I want to iterate n times in Java, I write: for (i = 0; i < n; i++) { // do stuff } In Python, it seems the standard way to do this is: for x in range(n): # do stuff As always, Python is more concise and more readable. But the x bothers me, as it is unnecessary, and PyDev generates a warning, since x is never used. Is ...

Iterating over json object for drawing a column chart?

I use, google.load('visualization', '1', {'packages': ['columnchart']}); //google.setOnLoadCallback(drawChart); function drawChart(response) { alert(response.customerlist); var data = new google.visualization.DataTable(); data.addColumn('string', 'dbZipcode'); data.addColumn('string', 'countusers'); data.addRows(resp...

Am i doing this iteration right in javascript?

Consider the two implementations below, data.addRows([ ['2004', 1000], ['2005', 1170], ['2006', 660], ['2007', 1030] ]); The above works (ie) it gets me what i want. and my implementation is, for (var i = 0; i < 10; i++) { data.addRows['row'+i,i]; } Is this a valid for loop or what am i doing wrong? I am usin...

Why can't i do this iteration with json data?

I tried this, var rows = []; for (var i = 0; i < 10; i++) { rows.push(['row' + i, i]); } data.addRows(rows); This seems to work but when i do the same with json, var data = new google.visualization.DataTable(); data.addColumn('string', 'dbZipcode'); data.addColumn('number', 'countusers'); var rows = [...

PHP equivalent to Python's enumerate()?

In Python I can write: for i, val in enumerate(lst): print i, val The only way I know how to do this in PHP is: for($i = 0; $i < count(lst); $i++){ echo "$i $val\n"; } Is there a cleaner way in PHP? ...

mysql : loop over tables and alter table add index

I have ~1000 tables that start with the same prefix : table_prefix_{SOME_ID} (i can take the ids from another table) what is the fast way to loop over all the tables in mysql and do : ALTER TABLE `table_prefix_{some_id}` ADD INDEX `fields` (`field`) ...

Iterating through textbox controls in a panel C#

I have seen many others with similar problems but I cannot find the flaw in my logic here. Any help would be greatly appreciated. I have a Panel which I have added numerous label and textbox controls to, ie: myPanel.Controls.Add(txtBox); These controls are created and added in a method called previous to the iteration method. I...

Is a concurrency approach a good idea for speeding a long iteration?

I have an app that does an iteration to create points on a graph over time. While I'm gathering data for each point across the x-axis I also must execute a recursive lookup which effectually means I have a loop inside another loop. This is not scaling too well. I don't see a lot of examples of using a "divide and conquer" solution on it...

Is it possible to merge iterators in Java?

Is it possible to merge iterators in Java? I have two iterators and I want to combine/merge them so that I could iterate though their elements in one go (in same loop) rather than two steps. Is that possible? Note that the number of elements in the two lists can be different therefore one loop over both lists is not the solution. Ite...

Domain class iteration in grails

Hi, I have the following relationship between two domain classes: class Emp { String name hasMany = [itemsell:Item, itembuy:Item] } class Item { String name } And I need to know what items are common to both collections for a given Emp (itemsell and itembuy); how can I do such iteration? Thanks ...

PHP: list number of times a word was found?

I got a custom log, roughly 29MBs of user's data, including user agent. I want to parse through it (essentially just search) and find how many occurances of say, "Firefox" or "MSIE" appear in it, like a mini log parser. This is where I am stumped.. What I was getting at is explode()ing newlines, and iterate through the array, use: if ...

Cycling through enums in MySQL

Hey guys, I have a table in my database with an enum column with 3 values: ('Offline', 'Online', 'Expired') I want to be able to do an update that cycles the value of the this column to the next value in the list... and wrap back to the start. i.e. 'Offline' will change to 'Online' 'Online' will change to 'Expired' 'Expired' w...

jQuery - Iteration problem

This is probaby really easy for you guys. Its a real hassle for me.. I want to add a new link next to all of my other links. Could someone help me out? Please!? http://jsfiddle.net/Ahndm/ ...