In my Python program, I was told that this code snippet:
listOfNumbers = input() # (This inputs a space separated list of integers)
listOfNumbers = listOfNumbers.split()
for x in range(0, len(listOfNumbers)):
listOfNumbers[x] = int(x)
Can be replaced by this one-liner:
listOfValues = [int(x) for x in input().split()]
I am new to Python so I don't know many code-shortening techniques or methods, so I started to analyse the snippet given.
I am confused about why part of the line is wrapped in square brackets: [int(x) for x in input().split()]
What do the [
and ]
at the start and end of that section of code do?