Thursday, 8 August 2013

Pythonic way of handling string formatted loop

Pythonic way of handling string formatted loop

I have the following code, and the idea is to be able to iterate over root
for each string in some_list[j]. The goal is to stay away from nested for
loops and learn a more pythonic way of doing this. I would like to return
each value for the first item in some_list then repeat for the next item
in some_list.
for i, value in enumerate(root.iter('{0}'.format(some_list[j])))
return value
Any ideas?
EDIT: root is
tree = ElementTree.parse(self._file)
root = tree.getroot()

No comments:

Post a Comment