Lists of lists traversal
Cliff Crawford
cjc26 at nospam.cornell.edu
Mon Dec 20 19:48:03 EST 1999
Pada 20 Dec 1999 21:17:27 GMT, Kaleissin bilang:
|
| What I would do in your case:
|
| listpos = 0
| while listpos < len(list_of_lists):
| list_of_lists[listpos] = reduce(lambda x, y: x+y, list_of_lists[listpos])
| listpos = listpos + 1
|
| This destroys the original lists btw. To keep them, append the resulting
| sum to some other list instead of replacing the list with it as above.
| You could use a for instead of the while too, in that case.
|
| It might not be very effective but it looks nice... list comprehension
| version, anyone?
[reduce(lambda x, y: x+y, l) for l in list_of_lists]
:-)
--
cliff crawford http://www.people.cornell.edu/pages/cjc26/
-><- "You and your stupid orthography" -- Mark
More information about the Python-list
mailing list