I am quite new to programming and don't understand a lot of concepts. Can someone explain to me the syntax of line 2 and how it works? Is there no indentation required? And also, where I can learn all this from?
string = #extremely large number
num = [int(c) for c in string if not c.isspace()]
That is a list comprehension, a sort of shorthand for creating a new list. It is functionally equivalent to:
num = []
for c in string:
if not c.isspace():
num.append(int(c))
It means exactly what it says.
num = [ int( c)
"num" shall be a list of: the int created from each c
for c in string
where c takes on each value found in string
if not c .isspace() ]
such that it is not the case that c is a space (end of list description)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With