Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. list1 = ["a", "b", "c", "d"]
  2. list2 = [1, 2, 3]
  3.  
  4. [a b c 1 2]
  5. [a b c 1 3]
  6. [a b c 2 3]
  7. [a b d 1 2]
  8. [a b d 1 3]
  9. [a b d 2 3]
  10. [a c d 1 2]
  11. [a c d 1 3]
  12. [a c d 2 3]
  13. [b c d 1 2]
  14. [b c d 1 3]
  15. [b c d 2 3]
  16.  
  17. import itertools
  18. from itertools import combinations
  19.  
  20. def combi(arr, r):
  21. return list(combinations(arr, r))
  22.  
  23. # Driver Function
  24. if __name__ == "__main__":
  25. a = ["a", "b", "c", "d"]
  26. r = 3
  27. a= combi(arr, r)
  28. print (a)
  29. b = [1, 2, 3]
  30. s =2
  31. b = combi(brr, s)
  32. print (b)
  33. crr = a + b
  34. print (crr)
  35. c = combi(crr, 2)
  36. print (c)
  37. for i in range(len(c)):
  38. for j in range(len(c)):
  39. print c[i][j]
  40. print 'n'
  41.  
  42. list1 = ["a", "b", "c", "d"]
  43. list2 = [1, 2, 3]
  44.  
  45. import itertools
  46.  
  47. comb1 = itertools.combinations(list1, 3)
  48. comb2 = itertools.combinations(list2, 2)
  49. result = itertools.product(comb1, comb2)
  50. result = [list(itertools.chain.from_iterable(x)) for x in result]
  51.  
  52. [['a', 'b', 'c', 1, 2],
  53. ['a', 'b', 'c', 1, 3],
  54. ['a', 'b', 'c', 2, 3],
  55. ['a', 'b', 'd', 1, 2],
  56. ['a', 'b', 'd', 1, 3],
  57. ['a', 'b', 'd', 2, 3],
  58. ['a', 'c', 'd', 1, 2],
  59. ['a', 'c', 'd', 1, 3],
  60. ['a', 'c', 'd', 2, 3],
  61. ['b', 'c', 'd', 1, 2],
  62. ['b', 'c', 'd', 1, 3],
  63. ['b', 'c', 'd', 2, 3]]
  64.  
  65. >>> from itertools import combinations
  66. >>> list1 = ["a", "b", "c", "d"]
  67. >>> list2 = [1, 2, 3]
  68. >>> [[*x, *y] for x in combinations(list1, 3) for y in combinations(list2, 2)]
  69. [['a', 'b', 'c', 1, 2], ['a', 'b', 'c', 1, 3], ['a', 'b', 'c', 2, 3], ['a', 'b', 'd', 1, 2], ['a', 'b', 'd', 1, 3], ['a', 'b', 'd', 2, 3], ['a', 'c', 'd', 1, 2], ['a', 'c', 'd', 1, 3], ['a', 'c', 'd', 2, 3], ['b', 'c', 'd', 1, 2], ['b', 'c', 'd', 1, 3], ['b', 'c', 'd', 2, 3]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement