Python: Iterate over list of tuples
examples/python/iterate_list_of_tuples.py
pair = [ ('fname', 'Foo'), ('lname', 'Bar'), ('email', 'foo@bar.com'), ] for p in pair: print('{} : {}'.format(p[0], p[1])) for p in pair: print('{} : {}'.format(*p)) for field, value in pair: print('{} : {}'.format(field, value))
And the output will be:
fname : Foo lname : Bar email : foo@bar.com fname : Foo lname : Bar email : foo@bar.com fname : Foo lname : Bar email : foo@bar.com
Published on 2019-01-18
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post