def number_of_cases(list_data):
from itertools import combinations_with_replacement
mylist = list_data
result = list(combinations_with_replacement(mylist, 2))
return(result)
def main():
result = number_of_cases(['a', 'b'])
print(result)
結果:以下のように私は組み合わせの間にスペースを望んでいない以下のようにコードを作成する方法は?
>>> main()
[('a', 'a'), ('a', 'b'), ('b', 'b')]
... ..結果以下のようにするコードを作成する方法 ?
>>> a = ['a', 'b', 'c']
['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']'
>>> a = ['a', 'a']
['aa']
>>> a = [1, 2, 3, 'a']
['11', '12', '13', '1a', '21', '22', '23', '2a', '31', '32', '33', '3a', 'a1', 'a2', 'a3', 'aa']
は、 'X + y'同じように簡単ではないですか? – Barmar
なし、実施例の一つは整数と文字列の組み合わせを持っていたので – wim
方法combinations_with_replacement([1,2,3におけるxの '[ "{0} {1}" 形式(x、y)は、Yについて、」 a ']、2)] 'Python 2でも動作させるには? – JohanL