0

Hello.
mylist = [6, '/', 3, '+', 9, '+', 8, '+', 1, '/', 2]
How can i delete that list indexes?
I tried:

    def clear(self, event):
        global numbers
        for i in numbers:
            print i
            del numbers[i]

But it didn't work:

   File "./kivycal", line 83, in clear
     del numbers[i]
 TypeError: list indices must be integers, not str

What can i do for that?

3
Contributors
5
Replies
18
Views
2 Years
Discussion Span
Last Post by Niloofar24
Featured Replies
  • To empty the list, use numbers[:] = [] Read More

  • 1

    mylist = [6, '/', 3, '+', 9, '+', 8, '+', 1, '/', 2] print(mylist) # replace mylist with an empty list mylist = [] print(mylist) # --> [] mylist = [6, '/', 3, '+', 9, '+', 8, '+', 1, '/', 2] # delete part of a list, keep the first … Read More

1
mylist = [6, '/', 3, '+', 9, '+', 8, '+', 1, '/', 2]
print(mylist)
# replace mylist with an empty list
mylist = []
print(mylist)   # --> []

mylist = [6, '/', 3, '+', 9, '+', 8, '+', 1, '/', 2]
# delete part of a list, keep the first 7 elements
del mylist[7:]
print(mylist)   # --> [6, '/', 3, '+', 9, '+', 8]

mylist = [6, '/', 3, '+', 9, '+', 8, '+', 1, '/', 2]
# delete part of a list, keep the last 3 elements
del mylist[:-3]
print(mylist)   # --> [1, '/', 2]

Edited by vegaseat

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.