Why first line create a lists of list and second a normal list? How can I create a normal list using comprehensions?
list45 = [input("first line: ").split()]
words2 = input("second line: ")
list46 = words2.split()
print(list45)
print(list46)
Output
first line: my first line
second line: my second line
[['my', 'first', 'line']]
['my', 'second', 'line']
CodePudding user response:
list45 = [input("Second line: ").split()]
This takes an input, splits the string, the output of which is a list, and puts it inside of another list. This is because you have square brackets surrounding it, which denote a list.
list46 = words2.split()
This just returns the result of the split function, which is a list.