[Tutor] Creating lists with 3 (later4) items occuring only once
marcus lütolf
marcus.luetolf at bluewin.ch
Fri Sep 18 17:41:52 CEST 2015
dear pythonistas
in the code below
>>> import string, itertools
>>> s = ['ab','ac','bc','ad','ae','de']
>>> count = 0
>>> for startlist in itertools.combinations(s, 3):
>>> count = count + 1
>>> stl = list(startlist)
>>> print count, stl
>>> for pair in s:
>>> x = stl.count(pair)
>>> print x, pair
the variable stl produces 20 lists. The variable x counts how many times the items of s occur in each of the 20 lists.
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'?
My further task will be expand s to all 26 letters oft he alphabet (giving 325 items) and the to eliminate all list in which the items in s occur more than once.
Thank you for help, Marcus.
---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus
More information about the Tutor
mailing list