0

I have a list inside of a dict, and I tried to remove all the items in the list, but the even numbers still remain even after i used a for loop to remove everything.

queue=[{123:['s1','s2','s3','s4']},{1234:['s1','s2','s3','s4']}]
print('BEFORE:',queue)
for item in queue:
  for server,songs in item.items():
    if server==123:
        for sonk in songs:
          songs.remove(sonk)

print('AFTER:',queue)

My output is:

BEFORE: [{123: ['s1', 's2', 's3', 's4']}, {1234: ['s1', 's2', 's3', 's5']}]
AFTER: [{123: ['s2', 's4']}, {1234: ['s1', 's2', 's3', 's5']}]

Could anyone please explain whats wrong?

sanguinis
  • 21
  • 3

0 Answers0