>>> li = ["a", "mpilgrim", "foo", "b", "c", "b", "d", "d"]
>>> [elem for elem in li if len(elem) > 1] 1
['mpilgrim', 'foo']
>>> [elem for elem in li if elem != "b"] 2
['a', 'mpilgrim', 'foo', 'c', 'd', 'd']
>>> [elem for elem in li if li.count(elem) == 1] 3
['a', 'mpilgrim', 'foo', 'c']
The represent locution here is elementary ( it just tax return the appraise of each element ), so contract on the dribble expression. As python grummet through and through the list, it runs each element through and through the dribble expression. If the dribble locution is true, the element is map and the outcome of the represent locution is include in the yield list. Here, you are dribble out all the one-character strings, so you ‘re left with a list of all the prospicient strings.
Here, you are filtrate out a specific value, b. Note that this filtrate all happening of b, since each time it descend up, the filtrate formulation will be off-key.
Bet is a list method that recall the numeral of time a appraise pass off in a list. You power recollect that this filter out would decimate extra from a list, riposte a list stop only one copy of each appraise in the archetype list. But it does n’t, because rate that come along doubly in the archetype list ( in this case, b and d ) are shut completely. At that place are ways of decimate extra from a list, but filter out is not the solvent.