Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51889
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.028 |
| X-Spam-Evidence | '*H*': 0.94; '*S*': 0.00; 'detect': 0.07; 'remaining': 0.07; "'as',": 0.16; '1),': 0.16; '2),': 0.16; '4),': 0.16; "[('a',": 0.16; 'be:': 0.16; 'collections': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'wrote:': 0.18; 'trying': 0.19; '(the': 0.22; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'list:': 0.30; 'matching': 0.30; 'subject:list': 0.30; "i'm": 0.30; 'end,': 0.31; 'initiated': 0.31; 'there,': 0.34; 'subject:from': 0.34; 'received:84': 0.35; 'but': 0.35; 'there': 0.35; 'doing': 0.36; 'subject:?': 0.36; 'example,': 0.37; 'list': 0.37; 'list.': 0.37; 'to:addr:python-list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'remove': 0.60; 'reaching': 0.61; 'first': 0.61; 'email addr:gmail.com': 0.63; 'information': 0.63; 'skip:n 10': 0.64; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'hand': 0.80; 'counts': 0.83; 'reply- to:addr:python.org': 0.84; 'hands': 0.96 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=XqLDZz19 c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=K2DDQYBT4xIA:10 a=8DsZ-cz6YY0A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=4ulmc5lJVbUA:10 a=pGLkceISAAAA:8 a=jamr0bK5mnEwCoB_Lz8A:9 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Sat, 03 Aug 2013 22:06:15 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Removing matching items from a list? |
| References | <6c0bdea5-23bd-4854-8016-4bf0af3b7d0e@googlegroups.com> |
| In-Reply-To | <6c0bdea5-23bd-4854-8016-4bf0af3b7d0e@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | python-list@python.org |
| 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.171.1375563983.1251.python-list@python.org> (permalink) |
| Lines | 33 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1375563983 news.xs4all.nl 15897 [2001:888:2000:d::a6]:41659 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:51889 |
Show key headers only | View raw
On 03/08/2013 21:12, kevin4fong@gmail.com wrote:
>
>
> Basically, I'm trying to find out how to remove matching items from a list. But there doesn't seem to be any information on how to go about doing this specific function.
>
> For example, what I want is:
>
> let's say there is a list:
>
> pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
>
> So up there, my list, which is named pHands[0] has ten items in it.
>
> I'm trying to make a function where a search is initiated into the list and any matching items with a first matching number/letter reaching four are removed
>
> So in the end, ad, ac, as, ah (the four a's) will all be deleted/removed from the list. I need the list to automatically detect if there are four matching first letter/numbers in the items in the list.
>
> The remaining list will be: pHands[0] = ['7d', '8s', '9d', 'td', 'js', 'jd']
>
>>> hands = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
>>> from collections import Counter
>>> counts = Counter(hand[0] for hand in hands)
>>> counts
Counter({'a': 4, 'j': 2, 't': 1, '7': 1, '9': 1, '8': 1})
>>> counts.most_common()
[('a', 4), ('j', 2), ('t', 1), ('7', 1), ('9', 1), ('8', 1)]
So there are 4 aces.
>>> hands = [hand for hand in hands if hand[0] != 'a']
>>> hands
['7d', '8s', '9d', 'td', 'js', 'jd']
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Removing matching items from a list? kevin4fong@gmail.com - 2013-08-03 13:12 -0700
Re: Removing matching items from a list? kevin4fong@gmail.com - 2013-08-03 13:16 -0700
Re: Removing matching items from a list? woooee@gmail.com - 2013-08-03 13:27 -0700
Re: Removing matching items from a list? Roy Smith <roy@panix.com> - 2013-08-03 17:02 -0400
Re: Removing matching items from a list? MRAB <python@mrabarnett.plus.com> - 2013-08-03 22:06 +0100
Re: Removing matching items from a list? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-03 22:37 +0000
Re: Removing matching items from a list? Roy Smith <roy@panix.com> - 2013-08-03 19:06 -0400
Re: Removing matching items from a list? Chris Angelico <rosuav@gmail.com> - 2013-08-04 00:35 +0100
Re: Removing matching items from a list? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-04 00:25 +0000
Re: Removing matching items from a list? kevin4fong@gmail.com - 2013-08-03 17:33 -0700
Re: Removing matching items from a list? kevin4fong@gmail.com - 2013-08-03 17:34 -0700
Re: Removing matching items from a list? kevin4fong@gmail.com - 2013-08-03 17:23 -0700
Re: Removing matching items from a list? kevin4fong@gmail.com - 2013-08-03 17:29 -0700
Re: Removing matching items from a list? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-04 00:40 +0000
Re: Removing matching items from a list? kevin4fong@gmail.com - 2013-08-03 17:32 -0700
Re: Removing matching items from a list? kevin4fong@gmail.com - 2013-08-03 17:33 -0700
Re: Removing matching items from a list? Dave Angel <davea@davea.name> - 2013-08-04 01:53 +0000
csiph-web