I'm having trouble converting a input into a list in python.
AYGSU
DOMRA
CPFAS
XBODG
WDYPK
PRXWO
What I need is to convert the code above into a 6x5 list.
I'm having trouble converting a input into a list in python.
AYGSU
DOMRA
CPFAS
XBODG
WDYPK
PRXWO
What I need is to convert the code above into a 6x5 list.
Here you can take advantage of the .split
function for string objects:
list_result = [[c for c in x] for x in input().split()]
"""
Result:
[['A', 'Y', 'G', 'S', 'U'],
['D', 'O', 'M', 'R', 'A'],
['C', 'P', 'F', 'A', 'S'],
['X', 'B', 'O', 'D', 'G'],
['W', 'D', 'Y', 'P', 'K'],
['P', 'R', 'X', 'W', 'O']]
"""
I'm using two list comprehensions. The first goes through and splits your input into individual words, the inner list comprehension splits each word into a list of its characters.