September 19, 2020

Python Datastructures Quickref

python

Array

An Array data structure is an ordered set of values of the same type

adding at the end
arr.append(item)
removing at 2nd position
arr.pop(2)
removing 1st occurrence
arr.remove(item)

Slice operation

List

Set

HashTable (Dictionary)

iteration
for key, value in dict.iteritems():
    temp = [key,value]
    dictlist.append(temp)

Conversion

keys to list
list(dict.keys())
values to list
list(dict.values())

Tree

Queue

Stack