Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
For Loop in List
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Dave Angel, post: 5071022"] What version of Python? It'd be only polite if you actually included the traceback, instead of paraphrasing the error. let's examine the code that generates the syntax error. for i=list2 in list1: That doesn't match any of the grammar of Python, so it gives a syntax error. How could the compiler have interpreted it? Perhaps it could have thrown out the 'for' and the colon. That would be equivalent in this case to: i = False or we could toss out the "=list2" but that would give us your first loop. If I were doing this, I'd do something like (untested): temp = list1[:] #make a shallow copy of the list, so we're not modifying the original while temp print temp[:3] temp = temp[3:] I think you could do something similar with zip, but I don't have the energy this morning. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
For Loop in List
Top