Is there a way to make this pythonic.
the_list = [1,2,3,4,5]
for x in the_list
y= get_handler(x)
#do something with x and y
Basically is there a simpler way to put the get_handler in the for deceleration?
ideally something readable like:
for x, get_handler(x) in the_list:
#do whatever
A working, but non readable solution:
the_list = [1,2,3,4,5]
for x, y in [(item, get_handler(item) for item in the_list )]:
# do something
No, “pythonic” means how normal python code would look like (see gnibbler’s answer: that is what “pythonic” is about).
If you want something that will do exactly what you want, you can do:
Then:
Do note that this doesn’t save you any typing at all. The only way it would save you typing is if you were using it for currying:
In which case it does save you typing:
Thus it might be reasonable if you happened to use it a lot. It would not be considered “pythonic” though.