pythonalphabetical

Print every two letters pairs in python3


I'm new to Python and I'm stuck in an exercise which tells me to provide a script printing every possible pairs of two letters, only lower case, one by line, ordered alphabetically and that is the closest thing that I could do

import string 
x=string.ascii_lowercase
y=list(x)
for i in y:
    print(i,end='')
    for g in y:
        print(g)


Solution

  • You need to print the i letter in the second for loop

    import string 
    x=string.ascii_lowercase
       
    for i in x:
        for g in x:
            print(i,g)
    

    So the program will go through every letter in the first loop and will print then the whole alphabet, one by one, as the second letter in the second loop