On 1/14/14 6:33 AM, Peter Otten wrote:
Python has no dedicated syntax for picking arbitrary items from a list
If you are only concerned about printing use format():

>>>items = ["alpha", "beta", "gamma", "delta"]
>>>print "{1} {3} {0}".format(*items)
beta delta alpha

.format also supports item access directly:

>>> items = ["alpha", "beta", "gamma", "delta"]
>>> print "{0[1]} {0[3]} {0[0]}".format(items)
beta delta alpha

It's clunkier in this example, but if you have more than one value being formatted, this (and the "{0.foo}" syntax) can make digging into nested data more convenient.

--
Ned Batchelder, http://nedbatchelder.com

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to