Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python trim zero off end of list

list1 = [48, 39, 23, 15, 11, 12, 5, 9, 7, 3, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0]

def pop_zeros(items):
    while items[-1] == 0:
        items.pop()

pop_zeros(list1)
pop_zeros(list2)
print(list1)

# Output:
[48, 39, 23, 15, 11, 12, 5, 9, 7, 3, 0, 0, 1, 0, 1]
Comment

PREVIOUS NEXT
Code Example
Python :: how to define number in python 
Python :: golang get started 
Python :: generating datafraoms using specific row values 
Python :: cpickle python 
Python :: add text to axis 
Python :: extract decimal number from string python 
Python :: correlation meaning 
Python :: aiohttps 
Python :: python melt 
Python :: get resolution of image python 
Python :: Uninstalling/removing a package is very easy with pip: 
Python :: python convert float to whole part of number 
Python :: numpy dataframe 
Python :: new paragraph python 
Python :: python count elements in sublists 
Python :: python ide 
Python :: flask add_url_rule 
Python :: sqlite python select with parameters 
Python :: python flatten a list of lists 
Python :: syntax of calloc 
Python :: image hashing 
Python :: upper python python.org 
Python :: print torch model python 
Python :: Python - How To Concatenate List of String 
Python :: qr decomposition python 
Python :: from random input python 
Python :: django venv activate 
Python :: delete plotted text in python 
Python :: classification algorithms pythonb´ 
Python :: delete content of table django 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =