Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

count zero

# Python3 code to move all zeroes
# at the end of array
 
# Function which pushes all
# zeros to end of an array.
def pushZerosToEnd(arr, n):
    count = 0 # Count of non-zero elements
     
    # Traverse the array. If element
    # encountered is non-zero, then
    # replace the element at index
    # 'count' with this element
    for i in range(n):
        if arr[i] != 0:
             
            # here count is incremented
            arr[count] = arr[i]
            count+=1
     
    # Now all non-zero elements have been
    # shifted to front and 'count' is set
    # as index of first 0. Make all
    # elements 0 from count to end.
    while count < n:
        arr[count] = 0
        count += 1
         
# Driver code
arr = [1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0, 9]
n = len(arr)
pushZerosToEnd(arr, n)
print("Array after pushing all zeros to end of array:")
print(arr)
 
# This code is contributed by "Abhishek Sharma 44"
Comment

PREVIOUS NEXT
Code Example
Python :: how to specify root geometry in tkinter 
Python :: keras name model 
Python :: display pil image on kivy canvas 
Python :: boto3 python s3 
Python :: slicing in python list 
Python :: Python Sum of an array in NumPy 
Python :: python selenium console log 
Python :: python create unreadable save file 
Python :: run python3 script in pytgon 
Python :: how to address null in python 
Python :: remove punctuation 
Python :: do while python 
Python :: Python Tkinter MenuButton Widget 
Python :: value list in django 
Python :: how should i learn python 
Python :: how to print python exception message 
Python :: recursion python examples 
Python :: python ON DUPLICATE KEY UPDATE 
Python :: python typing module list 
Python :: Python Pandas - How to write in a specific column in an Excel Sheet 
Python :: random.randint(0,20) + pyrthon 
Python :: parallel iteration python 
Python :: created by and updated by in django 
Python :: python run linux command and get output 
Python :: decimal to binary 
Python :: python compiler online 
Python :: python debugging 
Python :: python numpy how to empty array cycle 
Python :: cv2 assertion failed 
Python :: python remove all occurrence of an items from list 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =