iteration

C++ Filling an 1D array to represent a n-dimensional object based on a straight line segment

READ FIRST: I have rewritten this question with the help of a friend to be hopefully more specific in what is required. It can be found here I'm not very clear on n-cubes, but I believe they are what I am referring to as the square family. New Question Wording: Perhaps I wasn't clear enough. What I'm asking, is how to set a 1D array to...

jQuery returning two elements for each one it finds?

I'll start by saying I'm fairly new to jQuery. For the most part, I've found it intuitive and powerful, but this one circumstance has me thoroughly stumped. In the following method, the call to .each() returns two elements for every one found. It iterates over a set of table rows given IDs starting with the word, "communication," and fo...

Overlapping matches with finditer() in Python

Hi there, I'm using a regex to match Bible verse references in a text. The current regex is REF_REGEX = re.compile(''' (?<!\w) # Not preceded by any words (?P<quote>q(?:uote)?\s+)? # Match optional 'q' or 'quote' followed by many spaces (?P<book> (?:(?:[1-3]|I{1,3})\s*)?...

Class Property in for each

Hi guys, I am running from a problem while iterating over class properties. I have my first class: class Item private _UIN as integer = 0 private _Name as string = "" private _Category as ItemCategory = new ItemCategory() public Property UIN() as integer public property Name() as string public property Category() as ItemC...

Is there a more elegant way to act on the first and last items in a foreach enumeration than count++?

Is there a more elegant way to act on the first and last items when iterating through a foreach loop than incrementing a separate counter and checking it each time? For instance, the following code outputs: >>> [line1], [line2], [line3], [line4] <<< which requires knowing when you are acting on the first and last item. Is there a mo...

Parsing a list of dictionaries passed as a POST parameter

I have a list of python dictionaries that look like this: sandwiches = [ {'bread':'wheat', 'topping':'tomatoes', 'meat':'bacon'}, {'bread':'white', 'topping':'peanut butter', 'meat':'bacon'}, {'bread':'sourdough', 'topping':'cheese', 'meat':'bacon'} ] I want to pass this as a POST parameter to another Django app. What doe...

how to using "For" instead of "each" function in jquery

hi everybody! Today i'm very stack with a Work and jQ. I was get a morning for it but i can't resolve it :(. My Work here: <div class="container"> <p class="test">a</p> <div> <p class="test">a</p> </div> </div> In normal, i can using jQ with each function for select all <p class="test">a</p> EX: $(".test").each(...

Javascript E4X: How do I properly iterate over an attribute XMLList?

Hi, I have a problem with retrieving attribute values via E4x in javascript. Suppose a list of XML nodes like the following as the XMLObject: <node att1="value1" att2="value2" att3="value3" att4="value4"> <nodeChild><!CDATA[/* ... */]></nodeChild> /* more node childs */ </node> I properly accessed the nodes (in a loop) and i...

randomly generate variable names?

Hi Guys, I've got a problem.. I've got something like... if(condition(TEST) == true){ something (NAME) = new something(this); } This is inside a loop where there are many TEST variables being iterated through. I don't know how many and its possible each of them would need a "(NAME)" variable so basically I want to kno...

Iterating JavaScript object properties and arrays with for..in when ordering is important

This has been an age old question and I am aware of the usual reasons for not using for..in or perhaps even objects when any sort of ordering is needed, but I recently came across this article from MDC on the delete operator. Cross-browser issues Although ECMAScript makes iteration order of objects implementation-dependent, it may app...

Flash, ActionScript 3: get all movieclips that are containing in a movieclip

Lest just say i have a movieClip A which contains movieClips B1,B2,B3,B4,B5 I write code in A to receive all movieclips that a contains and like print there name. i tried this with no succes: for each (a:MovieClip in this) trace(a.name); does anyone know how to get this working. ** note the trace name is actually an example i ...

sqlite: go to previous record in result set?

In SQLite, with the standard C interface -- is there an easy way (even if a bit hack-ish) to iterate backwards in the result set? I'm trying to avoid caching the results myself. A solution I thought about was executing an extra query that would return the reverse results, but I'm not sure how efficient it would be. ...

adding a document to a Lucene index causes crash

i'm trying to index an mp3 file with only one ID3 frame. using CLucene and TagLib. the following code works fine: ... TagLib::MPEG::File file("/home/user/Depeche Mode - Personal Jesus.mp3"); if (file.ID3v2Tag()) { TagLib::ID3v2::FrameList frameList = file.ID3v2Tag()->frameList(); lucene::document::Document *document = new lucene...

Iterate a format string over a list

In Lisp, you can have something like this: (setf my-stuff '(1 2 "Foo" 34 42 "Ni" 12 14 "Blue")) (format t "~{~d ~r ~s~%~}" my-stuff) What would be the most Pythonic way to iterate over that same list? The first thing that comes to mind is: mystuff = [1, 2, "Foo", 34, 42, "Ni", 12, 14, "Blue"] for x in xrange(0, len(mystuff)-1, 3): ...

Python: Looping over One Dictionary and Creating Key/Value Pairs in a New Dictionary if Conditions Are Met

I want to compare the values of one dictionary to the values of a second dictionary. If the values meet certain criteria, I want to create a third dictionary with keys and value pairs that will vary depending on the matches. Here is a contrived example that shows my problem. edit: sorry about all the returns, but stack overflow is not...

Ruby flow control...

I can't find any useful resources online that breaks down Ruby's different flow-control options. Let's assume that I'm iterating over an array within in a method: def a_method things.each do |t| # control options? end end What are my different flow-control options here? How do they differ? retry return break next redo ...

Iterating over jQuery $(this).attr('class').split(" ") gives odd results

Hello, I've got a page where I'm trying to fetch arrays of classes for lots of divs which share a common class. For example: <div class="common lorem ipsum"></div> <div class="common dolor sit"></div> <div class="common hello world"></div> I want to fetch each common class div and get an Array of it's classes. At the moment, I'm doi...

Convert nested for-loops into single LINQ statement

Hi, can someone please help me turn this nested structure into a single LINQ statement? EventLog[] logs = EventLog.GetEventLogs(); for (int i = 0; i < logs.Length; i++) { if (logs[i].LogDisplayName.Equals("AAA")) { for (int j = 0; j < logs[i].Entries.Count; j++) ...

PHP arrays break apart and rebuild

A bit of background The project I am working on requires me to build a dynamic form, essentially a page is created and from there a user can add as many news articles to that page as they wish, my issue is that this is an inherited system and I have to jump through a million different hoops, one of which is the string sanitation, they w...

How to iterate over a string in c?

Right now I'm trying this: #include <stdio.h> int main(int argc, char *argv[]){ if (argc != 3){ printf("Usage: %s %s sourcecode input", argv[0], argv[1]); } else { char source[] = "This is an example."; int i; for (i = 0; i < sizeof(source); i++){ printf("%c", source[i]); ...