-1

I know that a list/dictionary can be emptied by re-initializing new objects, but I want to keep the initial objects.

  1. Also in Python 3 a list can be empty(removed) all elements, by using clear(). But how can be done in Python 2.7 ?

  2. Remove all keys from a dictionary ?

user3541631
  • 3,686
  • 8
  • 48
  • 115

1 Answers1

1

for a list:

l[:] = [] 

keeps the same object but empties the contents

gelonida
  • 5,327
  • 2
  • 23
  • 41