jaycodez
jaycodez

Reputation: 1919

Python - How to clear a integer from a list completely?

# Assign list "time" with the following time values.    
time = [15, 27, 32, 36.5, 38.5, 40.5, 41.5, 42, 43.5, 45.5, 47.5, 52.5]
# Remove 1st value(0) from the list
time[0] = []
# Show time
time
[[], 27, 32, 36.5, 38.5, 40.5, 41.5, 42, 43.5, 45.5, 47.5, 52.5]
# Print time 
print(time)
[[], 27, 32, 36.5, 38.5, 40.5, 41.5, 42, 43.5, 45.5, 47.5, 52.5]

I'm just following what the tutorial has taught me so far:
http://docs.python.org/py3k/tutorial/introduction.html#lists

Upvotes: 2

Views: 6271

Answers (4)

njzk2
njzk2

Reputation: 39406

Actually, if you want to do as the example suggests, you'd be doing

time[0:1] = []

Upvotes: 1

Lennart Regebro
Lennart Regebro

Reputation: 172249

For completeness:

time.remove(15)

But in this case I'd use:

del time[0]

Upvotes: 4

aqua
aqua

Reputation: 3375

There are literally countless ways to do this.

I prefer time = time[1:]

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

You want del for this.

del time[0]

Upvotes: 8

Related Questions