Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34260
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'assign': 0.07; 'item.': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:few': 0.09; 'terry': 0.09; 'variables,': 0.09; 'dec': 0.15; 'assigns': 0.16; 'folks,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'items.': 0.17; 'jan': 0.18; 'work,': 0.22; "i'd": 0.22; 'this:': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'common': 0.26; 'am,': 0.27; 'separate': 0.27; 'header:X-Complaints-To:1': 0.28; 'subject:/': 0.28; 'subject:list': 0.28; 'chris': 0.28; 'daniel': 0.30; 'to:addr :python-list': 0.33; "can't": 0.34; 'list': 0.35; 'pm,': 0.35; 'something': 0.35; 'received:org': 0.36; 'but': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'first': 0.61; 'anywhere.': 0.84; 'idiom': 0.84; 'received:fios.verizon.net': 0.84; 'does?': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: assign only first few items of a tuple/list |
| Date | Tue, 04 Dec 2012 17:18:25 -0500 |
| References | <CADjSo4TP03MTF_8Htn-N4xNV1zB08wTK7geLvxU0jYX_FXUqmg@mail.gmail.com> <CAPTjJmr+UB0phzuWoNYQxo8R3CQrVgMsH=vUf26MV7c+P+uKtg@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-173-75-251-66.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 |
| In-Reply-To | <CAPTjJmr+UB0phzuWoNYQxo8R3CQrVgMsH=vUf26MV7c+P+uKtg@mail.gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.480.1354659526.29569.python-list@python.org> (permalink) |
| Lines | 24 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1354659526 news.xs4all.nl 6853 [2001:888:2000:d::a6]:38558 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:34260 |
Show key headers only | View raw
On 12/4/2012 4:36 PM, Chris Angelico wrote: > On Wed, Dec 5, 2012 at 8:25 AM, Daniel Fetchinson > <fetchinson@googlemail.com> wrote: >> Hi folks, I swear I used to know this but can't find it anywhere. >> Say I have a list x = [ 1,2,3,4,5 ] and only care about the first two items. >> I'd like to assign the first two items to two variables, something like, >> >> a, b, _ = x >> >> but the above will not work, of course, but what is the common idiom >> for this that does? > > Try this: > > a, b, *_ = x > > Assigns 1 to a, 2 to b, and [3,4,5] to _ Or a, b = x[0:2]; depending on whether you do or do not want the remainder as a separate item. -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: assign only first few items of a tuple/list Terry Reedy <tjreedy@udel.edu> - 2012-12-04 17:18 -0500
csiph-web