1

I have a dictionary with lists as values:

foo = {5:[1,2,3]}

I want to add 1 to key as well as values and for that, I did this :

bar = {}
for k,v in a.items():
    z = []
    for i in v:
        z.append(i+1)
    bar[k+1] = z

Is there a better way to do this and does that method save runtime?

Excpected Result:

bar = {6: [2, 3, 4]}
Rahul
  • 10,830
  • 4
  • 53
  • 88
Yantra Logistics
  • 198
  • 4
  • 19

0 Answers0