[Tutor] Creating lists with 3 (later4) items occuring only once
Alan Gauld
alan.gauld at btinternet.com
Fri Sep 18 18:57:55 CEST 2015
On 18/09/15 16:41, marcus lütolf wrote:
>>>> s = ['ab','ac','bc','ad','ae','de']
>>>> for startlist in itertools.combinations(s, 3):
> How can I concatenate the 20 lists in oder to get one count for each of the items in s , for example 10 for 'ab'?
If I understand you correctly, something like this:
>>> counts = {'ab':0,'ac':0,'bc':0,'ad':0,'ae':0,'de':0}
>>> for combo in it.combinations(counts.keys(),3):
... for pair in combo:
... counts[pair] += 1
...
>>> counts
{'ac': 10, 'ab': 10, 'ae': 10, 'ad': 10, 'bc': 10, 'de': 10}
Is that what you want?
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list