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

26th Nov 2017, 8:40 AM
nitin israni
nitin israni - avatar
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']
26th Nov 2017, 9:05 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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)
26th Nov 2017, 9:30 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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)
26th Nov 2017, 5:34 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
what I want is this result ['a', '_' , ' a' , '_' ]
26th Nov 2017, 9:18 AM
nitin israni
nitin israni - avatar
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).
26th Nov 2017, 9:49 AM
nitin israni
nitin israni - avatar