Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!82.197.223.108.MISMATCH!feeder2.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.81.MISMATCH!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.04; 'subject:Python': 0.06; 'nested': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'alpha': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'delta': 0.24; 'received:comcast.net': 0.24; 'skip:{ 20': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; '>>>>': 0.31; 'but': 0.35; 'picking': 0.36; 'subject:?': 0.36; 'example,': 0.37; 'list': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'more': 0.64; 'otten': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: What's correct Python syntax? Date: Tue, 14 Jan 2014 07:19:42 -0500 References: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389701994 news.xs4all.nl 2914 [2001:888:2000:d::a6]:53128 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63893 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