Combinations between elements in two tuples in Python -


i have 2 tuples:

t1 = ('a', 'b') t2 = ('c', 'd', 'e') 

i wonder how create combinations between tuples, result should be:

ac, ad, ae, bc, bd, 

edit

using

list(itertools.combinations('abcd',2)) 

i generate list of combinations given string:

[('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd'), ('c', 'd')] 

if insert tuple instead of string following error occurs:

typeerror: sequence item 0: expected string, tuple found 

any suggestion how proceed?

itertools.product looking for:

>>> import itertools >>> t1 = ('a', 'b') >>> t2 = ('c', 'd', 'e') >>> list(itertools.product(t1, t2)) [('a', 'c'), ('a', 'd'), ('a', 'e'), ('b', 'c'), ('b', 'd'), ('b', 'e')] >>> [''.join(x) x in itertools.product(t1, t2)] ['ac', 'ad', 'ae', 'bc', 'bd', 'be'] 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -