I was trying to do an assignment operation in python single line for loop like
[a[i]=b[i] for i in range(0,len(b))]
This seems wrong. Is there a way I can use assignment operation in python single line for loop?
You are mixing two paradigms here, that of loop and list comprehension. The list comprehension will be
a = [x for x in b]
a = b[:]Copy lists can be done in many ways in Python.
Using slicing
a = b[:]
Using list()
a = list(b)
aandbhave the same length? And what is your use-case? Maybe there's an even better way (without loops or comprehensions).