-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,466
  • 7
  • 44
  • 93

1 Answers1

1

for a list:

l[:] = [] 

keeps the same object but empties the contents

gelonida
  • 4,811
  • 2
  • 17
  • 37