How to 'update' or 'overwrite' a python list
You may try this
alist[0] = 2014
but if you are not sure about the position of 123 then you may try like this:
for idx, item in enumerate(alist): if 123 in item: alist[idx] = 2014
What about replace the item if you know the position:
aList[0]=2014
Or if you don't know the position loop in the list, find the item and then replace it
aList = [123, 'xyz', 'zara', 'abc'] for i,item in enumerate(aList): if item==123: aList[i]=2014 break print aList
I think it is more pythonic:
aList.remove(123)aList.insert(0, 2014)
more useful:
def shuffle(list, to_delete, to_shuffle, index): list.remove(to_delete) list.insert(index, to_shuffle) returnlist = ['a', 'b']shuffle(list, 'a', 'c', 0)print list>> ['c', 'b']