Print('Occurrences of A: ' + str(my_unt('A'))) Print('Index of D in range 5 to 8 is: ' + str(my_deque.index('D', 5, 8))) Print('Index of D:' + str(my_deque.index('D'))) On the other hand the count() method counts the frequency of an item in the Deque. When no argument is passed with the element, it will choose the entire list, when a certain limit is specified, it checks the index in that limit. The index method is used to get the index of the first occurrence an element. There are some functions like index(), count() etc. Some functions in Deque are used to get information related to items. Print('Dequeue after pop operations: ' + str(my_deque)) Output Dequeue: deque()ĭequeue after pop operations: deque() The item related functions in Deque The pop() method is used to remove and return the right most element from the queue, and popleft() method is used to remove and return left most element from the queue. Like appending, there are two different types of pop functions. Print('Dequeue after appending: ' + str(my_deque)) Output Dequeue: deque()ĭequeue after appending: deque() The Popping functions on Deque #Insert some elements into the queue at first The append() method is used to add elements at the right end of the queue, and appendleft() method is used to append the element at the left of the queue. In this section we will see some functions of the Deque class The Appending functions on Deque To use it at first we need to import it the collections standard library module. The Dequeis a standard library class, which is located in the collections module. It uses the list object to create a deque.It provides O(1) time complexity for popping and appending. The Deque is basically a generalization of stack and queue structure, where it is initialized from left to right.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |