0
Can any help me with this code?
i want to copy all similar objects from one list to another at there places, but it add them to same place twice https://code.sololearn.com/cFUx1cxAC1SI/?ref=app
5 Answers
+ 4
Is this what you mean?
l = ['a', 'b', 'a', 'c']
l2 = [i*2 for i in l]
print(l2)
results in:
['aa', 'bb', 'aa', 'cc']
+ 4
l=['a','b','a','c']
l2=[]
for i in range(len(l)):
if l[i] != 'a':
l2.append('_')
else:
l2.append(l[i])
print(l2)
+ 2
Ok, the code above can be slightly modified to achieve that.
l = ['a', 'b', 'a', 'c']
l2 = ['_', '_', '_', '_']
for i in range(len(l)):
if l[i] != 'a':
l2[i] = '_'
print(l2)
+ 1
what I want is this result
['a', '_' , ' a' , '_' ]
0
thanks for your efforts but , here you are making a new( l2 ), that is not possible in my case. what I need is to edit a list (l2).