We can separate the output of combinations in Python in a few different ways:
from itertools import combinations
sample_list = [1, 2, 3, 4]
comb_list = list(combinations(sample_list, 2))
# Output: [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
from itertools import combinations
sample_list = [1, 2, 3, 4]
comb_list = combinations(sample_list, 2)
for i in comb_list:
print(i)
# Output:
# (1, 2)
# (1, 3)
# (1, 4)
# (2, 3)
# (2, 4)
# (3, 4)
from itertools import combinations
sample_list = [1, 2, 3, 4]
comb_list = combinations(sample_list, 2)
comb_str = '\n'.join([' '.join(map(str, tpl)) for tpl in comb_list])
print(comb_str)
# Output:
# 1 2
# 1 3
# 1 4
# 2 3
# 2 4
# 3 4
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-03-21 11:00:00 +0000
Seen: 7 times
Last updated: Mar 15 '22
How can popen() be used to direct streaming data to TAR?
In Python, can a string be utilized to retrieve a dataframe that has the same name as the string?
What is the method for merging field value and text into a singular line for display?
What is the method for programmatic access to a time series?