Removing matching items from a list?

kevin4fong at gmail.com kevin4fong at gmail.com
Sat Aug 3 16:16:52 EDT 2013


On Saturday, August 3, 2013 1:12:55 PM UTC-7, kevin... at 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']

Ah, I forgot to mention. This function will be used for other lists to so it can't specifically target "a" and needs to auto search for four matching first letters.

If it helps, the two letters/numbers in each item are strung together by the following function:

    for suite in range(4):
        for rank in range(13):
            deck.append(rankList[rank]+suitList[suite])

So they can be directly accessed using:
card[0] for the first letter/number
card[1] for the second  



More information about the Python-list mailing list