Finding length of items from a list
I have two list in a python
lis开发者_运维技巧t1=['12aa','2a','c2']
list2=['2ac','c2a','1ac']
First- Finding combinations of each two item from list1.
Second- Finding combinations of each two item from list2.
Third- Finding combinations of each two items from list1 and list2
Fourth- Calculating each combinations total length
Advice and help in Python is appreciated.
Thank you
import itertools as it
list1=['12aa','2a','c2']
list2=['2ac','c2a','1ac']
# First- Finding combinations of each two item from list1.
first = list(it.combinations(list1, 2))
# Second- Finding combinations of each two item from list2.
second = list(it.combinations(list2, 2))
# Third- Finding combinations of each two items from list1 and list2
third = list(it.product(list1, list2))
# Fourth- Calculating each combinations total length
for combination in first: # first, second, third
print combination, len(''.join(combination))
精彩评论