Compact way to assign values by slicing list in Python
Marco Buttu
marco.buttu at gmail.com
Thu Apr 3 09:50:48 EDT 2014
On 04/02/2014 01:17 AM, Mark Lawrence wrote:
> Came across this
> http://stackoverflow.com/questions/22756632/compact-way-to-assign-values-by-slicing-list-in-python?newsletter=1&nlcode=245176|202f
> - just curious what you guys and gals thought of the answers.
I prefere this one:
bar = ['a','b','c','x','y','z']
v1, _, _, v2, v3, _ = bar
I also like the solution with itemgetter:
v1, v2, v3 = itemgetter(0, 3, 4)(bar)
but I think it is less readable than the previous one
--
Marco Buttu
More information about the Python-list
mailing list