From 74c96c5dfb95c33858ba0f6e0b832f2135493abc Mon Sep 17 00:00:00 2001 From: Pratik Narola <35926958+Pratiknarola@users.noreply.github.com> Date: Tue, 1 Oct 2019 22:55:29 +0530 Subject: [PATCH] added deque data structure --- data_structures.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 data_structures.py diff --git a/data_structures.py b/data_structures.py new file mode 100644 index 0000000..227645c --- /dev/null +++ b/data_structures.py @@ -0,0 +1,24 @@ +#! /usr/bin/env python3 + +""" + python3 has many standards data strctures inbuilt and sometimes these are very useful. +""" + + +#deque -> doubly ended queue. + +#insertion and removal operations are faster. +# deque -> remove O(1) +# python list -> remove O(n) + +from collections import deque +q = deque() + +q.append('eat') +q.append('sleep') +q.append('code') + +q # output -> deque(['eat', 'sleep', 'code']) + +q.popleft() # deque -> ['sleep', 'code'] +