Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106276
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Michael Selik <michael.selik@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Drowning in a teacup? |
| Date | Sat, 02 Apr 2016 05:51:46 +0000 |
| Lines | 30 |
| Message-ID | <mailman.357.1459576691.28225.python-list@python.org> (permalink) |
| References | <ndmlj2$pb0$1@gioia.aioe.org> <ndnm9v$j07$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de sIizKUdtFzOxg/0scUqgVg8bzm3SziT0VP92P1D+M23A== |
| Return-Path | <michael.selik@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'matches': 0.07; 'strings.': 0.07; 'suggestions.': 0.09; '>>>': 0.15; 'key?': 0.16; 'keyword,': 0.16; 'list)': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'element': 0.18; '>': 0.18; '(in': 0.18; 'email addr:gmail.com>': 0.18; '>>>': 0.20; 'to:2**1': 0.21; 'elements': 0.23; 'sat,': 0.23; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; '(new': 0.29; 'relative': 0.30; "i'd": 0.31; 'post': 0.31; "can't": 0.32; 'list': 0.34; 'received:google.com': 0.35; 'something': 0.35; 'list,': 0.36; 'received:209.85': 0.36; 'beginning': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'list.': 0.37; 'front': 0.38; 'received:209': 0.38; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'snap': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=xAzsMyGKD1qTTxMbs3Un0bB/EvPDwtWjOlbiiuyMd1g=; b=Df/aUHUYnlV2fZXj9eAZSSxROcfrJ04LEmYAbzS3JObx/MJ0C0wXhUmKx5UfrwuAAM VgXSijGcmK2Og4dmumAajcVMQQR8grKmna/Q33r87tNTMclNgpvNeDzXfG32iKBTmD4X nyyNnHtFwvx6ahx6MfVJFFpQSPJjKsptMkMJAXbu5kNXHiOge5wOr2cdbGIFFKDf8phe YuAKHbGNYSI9lbLpfWywWdYofbYlrDw288VLOeuVM+VHVJLENqjaolrtbnkSkwUwM/W7 gADCJj9VJhJUcE5gYHp67DHfSZOGDIqOHIfbkODk+zANLL/qrDK4VkZuDwxB5sgwzkZT HhbA== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=xAzsMyGKD1qTTxMbs3Un0bB/EvPDwtWjOlbiiuyMd1g=; b=UObdpELdcXV2QtE2Gb7vZHc7POnawWpalHNA5LaOECaDI0tFUqZwig44VTlw0dZHMh 5tr36JA5JFjLUnS6WnUR8lqFx34OwsQpQeBFQDRDI+t7nBv3pU9Q5KplKiGj/X64PCJm lgvE4W6dwnuAsmP/+5+AGe3ukPdQWszieHoTpK1ucYPyoI2VMy4/3G2KMjWMoQsJ7rGv lfBu5FijHM/RpS6AMsOyM/kYuFV6WyEzsfeJrGlWonDr391OVaxwOyizCy/T9e5sactN s3u2zTrFQpOHz9Be6V4XxDhLROMYKIsdQlsHX45AhooXouT2yqgsOTbQa3G/8l4CO53s Dhrg== |
| X-Gm-Message-State | AD7BkJKh3XNOVW77W2JPx3tFo+HNycOlTiAgsc1RoKr9ixYcjX8e0xSnkmZoMrlHKGtaIf0lWTle/RoNiAPyKA== |
| X-Received | by 10.140.22.212 with SMTP id 78mr29425558qgn.77.1459576315326; Fri, 01 Apr 2016 22:51:55 -0700 (PDT) |
| In-Reply-To | <ndnm9v$j07$1@ger.gmane.org> |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.21 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:106276 |
Show key headers only | View raw
On Sat, Apr 2, 2016, 1:46 AM Vito De Tullio <vito.detullio@gmail.com> wrote:
> Fillmore wrote:
>
> > I need to scan a list of strings. If one of the elements matches the
> > beginning of a search keyword, that element needs to snap to the front
> > of the list.
>
> I know this post regards the function passing, but, on you specific
> problem,
> can't you just ... sort the list with a custom key?
>
> something like (new list)
>
> >>> sorted(['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x'],
> ... key=lambda e: not e.startswith('yes'))
> ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y']
>
> or (in place)
>
> >>> l = ['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x']
> >>> l.sort(key=lambda e: not e.startswith('yes'))
> >>> l
> ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y']
>
If the number of matches is small relative to the size of the list, I'd
expect the sort would be slower than most of the other suggestions.
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Drowning in a teacup? Fillmore <fillmore_remove@hotmail.com> - 2016-04-01 16:27 -0400
Re: Drowning in a teacup? Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-04-01 20:39 +0000
Re: Drowning in a teacup? Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-01 14:52 -0600
Re: Drowning in a teacup? MRAB <python@mrabarnett.plus.com> - 2016-04-01 21:45 +0100
Re: Drowning in a teacup? Michael Selik <michael.selik@gmail.com> - 2016-04-01 20:46 +0000
Re: Drowning in a teacup? Steven D'Aprano <steve@pearwood.info> - 2016-04-02 09:46 +1100
Re: Drowning in a teacup? Fillmore <fillmore_remove@hotmail.com> - 2016-04-02 00:03 -0400
Re: Drowning in a teacup? Vito De Tullio <vito.detullio@gmail.com> - 2016-04-02 07:45 +0200
Re: Drowning in a teacup? Michael Selik <michael.selik@gmail.com> - 2016-04-02 05:51 +0000
Re: Drowning in a teacup? Vito De Tullio <vito.detullio@gmail.com> - 2016-04-02 08:26 +0200
Re: Drowning in a teacup? Peter Otten <__peter__@web.de> - 2016-04-02 12:31 +0200
Re: Drowning in a teacup? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-04-02 12:53 +0100
Re: Drowning in a teacup? Michael Selik <michael.selik@gmail.com> - 2016-04-02 14:36 +0000
Re: Drowning in a teacup? Ned Batchelder <ned@nedbatchelder.com> - 2016-04-02 12:28 -0700
Re: Drowning in a teacup? Random832 <random832@fastmail.com> - 2016-04-02 15:54 -0400
Re: Drowning in a teacup? Steven D'Aprano <steve@pearwood.info> - 2016-04-03 12:33 +1000
Re: Drowning in a teacup? Ethan Furman <ethan@stoneleaf.us> - 2016-04-02 16:15 -0700
Re: Drowning in a teacup? Random832 <random832@fastmail.com> - 2016-04-02 19:19 -0400
csiph-web