fork download
  1. # your code goes here
  2. import itertools
  3. from functools import reduce
  4. import operator
  5. my_list = [2,10,13,23,11]
  6. r = 3 # Length of combinations
  7.  
  8. # Get all combinations of length r
  9. combinations_r = list(itertools.combinations(my_list, r))
  10. print(f"Combinations of length {r}: {combinations_r}")
  11. for comb in combinations_r:
  12. comb = list(comb)
  13. # print(comb)
  14. print(f"XOR{comb} = {reduce(operator.xor, comb)}")
  15.  
Success #stdin #stdout 0.09s 14092KB
stdin
Standard input is empty
stdout
Combinations of length 3: [(2, 10, 13), (2, 10, 23), (2, 10, 11), (2, 13, 23), (2, 13, 11), (2, 23, 11), (10, 13, 23), (10, 13, 11), (10, 23, 11), (13, 23, 11)]
XOR[2, 10, 13] = 5
XOR[2, 10, 23] = 31
XOR[2, 10, 11] = 3
XOR[2, 13, 23] = 24
XOR[2, 13, 11] = 4
XOR[2, 23, 11] = 30
XOR[10, 13, 23] = 16
XOR[10, 13, 11] = 12
XOR[10, 23, 11] = 22
XOR[13, 23, 11] = 17