Skip to content

Commit 93d82f9

Browse files
committed
Added a data structures notebook
1 parent be2be74 commit 93d82f9

File tree

2 files changed

+1322
-0
lines changed

2 files changed

+1322
-0
lines changed

snippets/data_structures.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,38 @@ def list_ex():
1515
# Lists also support concatenation
1616
print(my_non_empty_list + [5, 6, 11, 13])
1717

18+
# You can get the length of a list
19+
print(len(my_non_empty_list))
20+
21+
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
22+
print(letters)
23+
# You can replace some values by slices
24+
letters[2:5] = ['C', 'D', 'E']
25+
print(letters)
26+
27+
# Now remove them
28+
letters[2:5] = []
29+
print(letters)
30+
31+
# Searching for values in a list
32+
search_list = ['harambe', 'was', 'an', 'inside', 'job']
33+
34+
# Prints number of 'was' in the list
35+
print(search_list.count('was'))
36+
37+
# Prints the index of 'harambe'
38+
print(search_list.index('harambe'))
39+
40+
# Errors if not in list
41+
# print(search_list.index('justice'))
42+
1843

1944
def dict_ex():
2045
# Ways to initialize a dictionary
2146
my_dict = {}
2247

2348
def tuple_ex():
49+
# Tuples are immutable lists. It can't be changed in any way once it's created
2450
# Ways to initialize a tuple
2551
my_tuple = ()
2652

0 commit comments

Comments
 (0)