summaryrefslogtreecommitdiff
path: root/mit/data_structs.py
blob: 378e2c459991a101b4cf46c8907a3d6767c1178d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python3

# Tuples - Immutable - between ()

my_str = "XUXUBELEZA"
my_tuple = (2, "one", "three", 3.5)
tuple2 = (9, 10)
tuple3 = ("one",) # notice the extra comma
print(my_tuple + tuple2)

# Lists - looks like a lot like a tuple... between []
#         Usually homogeneous (but we can have different types)
#       - Big difference is that lists are mutable

a_list = []
b_list = [2, 'a', 3, 'b', True]
L = [2, 1, 3]
L2 = ['a', 'b', 'c']
L3 = L + L2

#########################################

i = 0
new_tup = ()
while i < len(my_tuple):
    print(my_tuple[i])
    new_tup += (my_tuple[i],)
    i+=1

print(my_tuple[0:-1])

print("#####################3")

#print(L)
L.append(10)
#print(L)
#L.extend(L2)
print(L3)
#print(L)

del(L3[3])  # Delete a specific inded
print(L3)
L3.pop()    # Delete the last item of the list
print(L3)
L3.remove('b') # Delete the 1st appearance of that item
print(L3)
my_list = list(my_str)
print(my_list)
print(my_str.split('B')) # Split a string on a specific character
print("_".join(my_list)) # Join string elements in a list to a string
print(sorted(L)) # Sort but not mutate the string
L.sort()    # Sort the list in place
print(L)