-3

I know there are several questions like this, but they dont describe exactly what I want. I need it for a task about a password generator. All itertools modules I know work like:

list1 = [1, 2] list2 = [3, 4]

it would print out: (1, 3)(1, 4)(2, 3)(2, 4)

But I also need (3, 1)(4, 1)(3, 2)(4, 2) ´ So basically (1, 0) and (0, 1) shouldnt be seen as the same combination.

Thanks in advance :)

Imran
  • 775
  • 7
  • 19
RedShady
  • 3
  • 1
  • Would `itertools.permutations` do what you want? https://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list – Jon Betts Aug 21 '20 at 11:08
  • 1
    Show us what you've tried. – Abhijit Sarkar Aug 21 '20 at 11:14
  • And one more thing: I somehow cannot join the tuples I get from itertools.combinations. They are all strings, with .join I get an empty output (it prints as many blank lines as passwords were generated) and if I do it with a for loop i get completely weird outputs, it for example prints the alphabet as many times as passwords were generated – RedShady Aug 21 '20 at 11:41
  • @JonBetts yes, this is exactly what I want, thank you! But still I cannot concat them to a string – RedShady Aug 21 '20 at 11:42

1 Answers1

-1

As per your need, I've constructed a program :

list1 = [1, 2]
list2 = [3, 4]
for i in list1:
    for j in list2:
        print((i,j),end=' ')
    for j in list2:
        print((j,i),end=" ")
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Thank you, but am I right that using itertools.permutations with one list with [1, 2, 3, 4] would do the same? – RedShady Aug 21 '20 at 11:51
  • What I actually forgot is that I also need things like aa, bb, cc etc, but i currently have no clue how to do all that efficient – RedShady Aug 21 '20 at 12:00