Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
57 lines (41 loc) · 1.23 KB

File metadata and controls

57 lines (41 loc) · 1.23 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Python code to demonstrate working of
# extend(), extendleft(), rotate(), reverse()
# importing "collections" for deque operations
import collections
# initializing deque
de = collections.deque([1, 2, 3])
# using extend() to add numbers to right end
# adds 4,5,6 to right end
de.extend([4, 5, 6])
# printing modified deque
print("The deque after extending deque at end is : ")
print(de)
# using extendleft() to add numbers to left end
# adds 7,8,9 to right end
de.extendleft([7, 8, 9])
# printing modified deque
print("The deque after extending deque at beginning is : ")
print(de)
# using rotate() to rotate the deque
# rotates by 3 to left
de.rotate(-3)
# printing modified deque
print("The deque after rotating deque is : ")
print(de)
# using reverse() to reverse the deque
de.reverse()
# printing modified deque
print("The deque after reversing deque is : ")
print(de)
# get right-end value and eliminate
startValue = de.pop()
print("The deque after popping value at end is : ")
print(de)
# get left-end value and eliminate
endValue = de.popleft()
print("The deque after popping value at start is : ")
print(de)
# eliminate element searched by value
de.remove(5)
print("The deque after eliminating element searched by value : ")
print(de)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.