开发者

Finding length of items from a list

开发者 https://www.devze.com 2023-01-19 21:34 出处:网络
I have two list in a python lis开发者_运维技巧t1=[\'12aa\',\'2a\',\'c2\'] list2=[\'2ac\',\'c2a\',\'1ac\']

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))
0

精彩评论

暂无评论...
验证码 换一张
取 消