0

** to run this program which add element into list ** error int object is not iterable

d={'a':[1,4]}

d['a']. extend (34)

Community
  • 1
  • 1
GursimranSe
  • 99
  • 2
  • 8

1 Answers1

1

d['a'] is a list. To add a single element to that list, either use append() or call extend() with an iterable (such as a list or a tuple):

d['a'].append(34)
d['a'].extend([34])

For further background, see What exactly are iterator, iterable, and iteration?

NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • @user9405787, This has nothing to do with dictionaries. `append` and `extend` are `list` methods. – jpp May 13 '18 at 09:12