I am relatively new to coding and python and I am trying to wrap my head round some concepts. One I am struggling on is the split() function and why these two pieces of code produce two different outputs
y = ["hello\n", "world\n", "python\n"]
x = [line.strip() for line in y]
print(x)
and
y = ["hello\n", "world\n", "python\n"]
for line in y:
x = [line.strip()]
print(x)
The first piece of code produces an output of
['hello', 'world', 'python']
Whilst the second produces
['python']
Does anyone know why this is, as to me they should do the same thing by both producing an output of
['python']
thanks