Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python deque

# deque -list-like container with fast appends and pops on either end
from collections import deque

queue = deque() # create deque
queue.append(2) # append right
queue.appenleft(1) # append left
queue.clear() # remove all elements --> len = 0
copy_queue = queue.copy() # create a shallow copy of the deque
queue.count(x) # count the number of deque elements equal to x
queue.extend([4, 5, 6]) # extend right by an iterable
queue.extendleft([1, 2, 3]) # extend left by an iterable

# More at: https://docs.python.org/3/library/collections.html#collections.deque

Comment

python dequeu

# Python code to demonstrate deque
     
   
from collections import deque
     
# Declaring deque
queue = deque(['name','age','DOB']) 
     
print(queue)
Comment

python deque

from collections import deque

arr = deque([1, 2])

# append left
arr.appendleft(1)

# append right
arr.append(3)

# count number of 1's in deque
print(arr.count(1))
# output 2

# added 3 new number to the left of deque
arr.extendleft([-1, -2, -3])
print(arr)
# output deque([-3, -2, -1, 1, 1, 2, 3])

# added 3 new number to the right of deque
arr.extend([4, 5, 6])
print(arr)
# output deque([-3, -2, -1, 1, 1, 2, 3, 4, 5, 6])

# insert 10 in the 3rd position
arr.insert(2, 10)
print(arr)
# output deque([-3, -2, 10, -1, 1, 1, 2, 3, 4, 5, 6])

# remove and return far right element
print(arr.pop())
# output 6

# remove and return far left element
print(arr.popleft())
# output -3

# reverse deque
arr.reverse()
print(arr)
# output deque([5, 4, 3, 2, 1, 1, -1, 10, -2])
Comment

deque python

# deque -list-like container with fast appends and pops on either end
from collections import deque

queue = deque() # create deque
queue.append(2) # append right
queue.appenleft(1) # append left
queue.clear() # remove all elements --> len = 0
copy_queue = queue.copy() # create a shallow copy of the deque
queue.count(x) # count the number of deque elements equal to x
queue.extend([4, 5, 6]) # extend right by an iterable
queue.extendleft([1, 2, 3]) # extend left by an iterable
Comment

PREVIOUS NEXT
Code Example
Python :: python if greater than and less than 
Python :: linear search algorithm in python 
Python :: dynamic array logic in python use 
Python :: cudart64_110.dll not found 
Python :: pytest use fixture without running any tests 
Python :: oops python self and making an object of a class and calling function 
Python :: how to check a string in if statement python 
Python :: crud python 
Python :: flask page 
Python :: python get file size 
Python :: dataframe names pandas 
Python :: python3 -m venv venv 
Python :: dijkstra algorithm 
Python :: rstrip python3 
Python :: Heroku gunicorn flask login is not working properly 
Python :: is enumerate python lazy 
Python :: save python pptx in colab 
Python :: locate certificate path python 
Python :: python str and repr 
Python :: output multiple LaTex equations in one cell in Google Colab 
Python :: convert only time to unix timestamp python 
Python :: exception: python in worker has different version 3.7 than that in driver 3.8, pyspark cannot run with different minor versions. please check environment variables pyspark_python and pyspark_driver_python are correctly set. 
Python :: pandas dro pow 
Python :: #finding the similarity among two sets and 1 if statement 
Python :: remove color from shapefile python 
Python :: pillow update image 
Python :: print is not working in python 
Python :: integer to binary python 16 bit 
Python :: django query column 
Python :: configparser error reading relative file path 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =