I have a list of lists, each list within the list contains 5 items, how do I change the values of the items in the list? I have tried the following:
for [ite
You could use enumerate()
:
for index, sublist in enumerate(execlist):
if sublist[0] == mynumber:
execlist[index][1] = myctype
execlist[index][2] = myx
execlist[index][3] = myy
execlist[index][4] = mydelay
# break
You can remove the #
if execlist
only contains at most one sublist whose first item can equal mynumber
; otherwise, you'll cycle uselessly through the entire rest of the list.
And if the itemnumbers
are in fact unique, you might be better off with a dictionary or at least an OrderedDict
, depending on what else you intend to do with your data.