0

Here my data :

data =  [ 
    ["Autofollow", "01:27:41:00", "00:00:00:00", "NameOfFile", "Rkey_", "00:00:00:00", "28/07/2021"],
    ["Autofollow", "01:27:41:00", "00:00:00:00", "NameOfFile2", "Rkey_", "00:00:00:00", "28/07/2021"] 
        ] 

here I generate my data according to the number i want :

dataRand = [random.choice(data) for i in range(20)]

And after that i want to increment my value Rkey_ with this function :

def UpRkey() :
    for index, value in enumerate(dataRand):
        value[4] = value[4] + str(index)
        print(value[4])

UpRkey() 

But when i run my program i have this result :

Rkey_ Rkey_ Rkey_1 Rkey_ Rkey_3 Rkey_0 Rkey_34 Rkey_05 Rkey_ Rkey_346 Rkey_ Rkey_3469 Rkey_ Rkey_8 Rkey_10 Rkey_813 Rkey_1014 Rkey_057 Rkey_12 Rkey_346911

can someone explain this behavior to me?

Yvs
  • 3
  • 2
  • You keep modifying the same list item over and over. Randomly choosing from the list doesn’t create *copies* of the list. There are only two list objects in use here throughout the entire program, to which you have several references. – deceze Aug 04 '21 at 18:47

0 Answers0