Data structures

    • collection of elements with defined order

    • flexible: elements can be added, removed, replaced: d.append('B')

    • indexed elements, zero-based: d[0]

read more ...


    • like lists that cannot be changed

    • ordered (indexed)

    • constant: elements cannot be changed


    • collection of unique elements (duplicated values are removed)

    • no particular order (no index)

    • flexible: elements can be added, removed, replaced: d.add('B')

    • logical operations between sets: d1.union(d2)

    • loop / test: if 'B' in d:

    • a set is like a dictionary with no values

    • like sets, but with the possibility to add data to each element: d['Mike']=('Berlin',1983)

    • no particular order (no index)

    • elements are unique (key-words)

    • flexible: elements and data can be added, removed, replaced

read more ...


d={} is an empty dictionary

d={'A'} is a set

d=set() is an empty set

d=() is an empty tuple

d=[] is en empty list

To check the data type use:


<type 'list'>

Convert data types

# check type

mylist = ['A', 'B', 'A']


<type 'list'>

# convert list to set


set(['A', 'B'])


<type 'set'>

# convert text-string into single element list

s = 'filename.txt'

myFileList = [s]


"if" check for data type

"if, else" data type testing

x = ['A', 'B']

if type(x) is list:

print('YES, x is a list')


print('NO, x is not a list')

YES, x is a list