ubuntu2004
Kernel: Python 3 (system-wide)
COSC 130 - Homework 05
Kyle Anderson
In [3]:
Problem 1: Argument Sort
In [4]:
In [5]:
Out[5]:
[5, 6, 2, 3, 7, 4, 0, 1]
In [6]:
Out[6]:
[5, 2, 4, 0, 1, 3]
Problem 2: Process Lines of Text
In [7]:
In [8]:
Out[8]:
[6, 174, 'Blah', 'Hello World', 7.37]
Problem 3: Processing File Input
In [9]:
In [10]:
Out[10]:
['Survived', 'Pclass', 'Name', 'Sex', 'Age', 'Fare']
[0, 3, 'Mr. Owen Harris Braund', 'male', 22, 7.25]
[1, 3, 'Miss. Laina Heikkinen', 'female', 26, 7.925]
[1, 2, 'Mrs. Nicholas Nasser', 'female', 14, 30.0708]
[1, 3, 'Miss. Marguerite Rut Sandstrom', 'female', 4, 16.7]
[1, 1, 'Miss. Elizabeth Bonnell', 'female', 58, 26.55]
[0, 3, 'Mr. William Henry Saundercock', 'male', 20, 8.05]
[0, 3, 'Mr. Anders Johan Andersson', 'male', 39, 31.275]
[0, 3, 'Miss. Hulda Amanda Adolfina Vestrom', 'female', 14, 7.8542]
[0, 3, 'Master. Eugene Rice', 'male', 2, 29.125]
[1, 2, 'Mr. Charles Eugene Williams', 'male', 23, 13.0]
In [11]:
Out[11]:
['carat', 'cut', 'color', 'clarity', 'price']
[0.36, 'Ideal', 'E', 'VS2', 1013]
[0.3, 'Fair', 'J', 'VS2', 416]
[1.22, 'Ideal', 'H', 'SI1', 6541]
[0.48, 'Good', 'G', 'SI1', 914]
[0.75, 'Ideal', 'J', 'VS1', 2300]
[0.31, 'Premium', 'H', 'VVS2', 802]
[2.48, 'Very Good', 'H', 'SI2', 15746]
[1.0, 'Good', 'D', 'SI1', 5469]
[0.51, 'Very Good', 'F', 'VS1', 1627]
Problem 4: Recursive Product
In [12]:
In [13]:
Out[13]:
2423520
Problem 5: Greatest Common Divisor
In [14]:
In [15]:
Out[15]:
12
30
20
1
Problem 6: Flattening Nested Lists
In [16]:
Out[16]:
[1, 8, 5, 6, 4, 9, 7, 2, 3]
In [17]:
Out[17]:
[1, 8, 5, 6, 4, 9, 7, 2, 3]
[1, 2, 3]
[1, 2, 4, 5, 6]
Problem 7: Binary Search
In [18]:
In [19]:
Out[19]:
[0, 0, 2, 2, 2, 2, 2, 3, 3, 4, 9, 12, 13, 17, 17, 18, 21, 21, 22, 22, 23, 23, 23, 24, 25, 26, 28, 30, 33, 37, 38, 39, 39, 41, 42, 42, 42, 43, 43, 43, 44, 44, 45, 45, 48, 49, 49, 50, 50, 50, 51, 51, 52, 53, 54, 54, 54, 55, 56, 57, 58, 58, 59, 64, 65, 67, 67, 70, 70, 71, 72, 72, 74, 76, 76, 77, 77, 78, 78, 79, 80, 82, 83, 83, 83, 84, 84, 85, 86, 88, 88, 90, 93, 93, 94, 95, 95, 98, 98, 99]
0 - True
1 - False
2 - True
3 - True
4 - True
5 - False
6 - False
7 - False
8 - False
9 - True
Problem 8: Quicksort
In [20]:
In [21]:
Out[21]:
[95, 94, 5, 8, 83, 73, 66, 30, 60, 60, 58, 15, 43, 39, 72, 99, 94, 54, 44, 26]
[5, 8, 15, 26, 30, 39, 43, 44, 54, 58, 60, 60, 66, 72, 73, 83, 94, 94, 95, 99]
In [22]:
Out[22]:
[23, 54, 36, 60, 62, 6, 1, 83, 25, 23, 99, 47, 83, 47, 63, 15, 63, 86, 52, 74]
[1, 6, 15, 23, 23, 25, 36, 47, 47, 52, 54, 60, 62, 63, 63, 74, 83, 83, 86, 99]
In [0]: