Quantcast
Channel: How can I partition (split up, divide) a list based on a condition? - Stack Overflow
Viewing all articles
Browse latest Browse all 41

Answer by Shikhar Mall for How can I partition (split up, divide) a list based on a condition?

$
0
0

Sometimes you won't need that other half of the list.For example:

import sysfrom itertools import ifiltertrustedPeople = sys.argv[1].split(',')newName = sys.argv[2]myFriends = ifilter(lambda x: x.startswith('Shi'), trustedPeople)print '%s is %smy friend.' % (newName, newName not in myFriends 'not ' or '')

Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>