-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lists_Control Flow_and_More.py
214 lines (130 loc) · 4.42 KB
/
Lists_Control Flow_and_More.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python
# coding: utf-8
# In[6]:
import csv
# be sure to update the path below to reflect your own environment!!
# also be sure that the code is properly indented after you paste it!
## made empty lists for rows
price_list = []
main_cost_list = []
num_doors_list = []
num_passenger_list = []
lugg_cap_list = []
safety_rating_list = []
class_of_vehicle = []
with open('/Users/RandyLeon/Desktop/cars-sample35.txt') as csvfile:
readCSV = csv.reader(csvfile)
for row in readCSV:
# print each row as read by the csv.reader function
price_list.append(row[0])
main_cost_list.append(row[1])
num_doors_list.append(row[2])
num_passenger_list.append(row[3])
lugg_cap_list.append(row[4])
safety_rating_list.append(row[5])
class_of_vehicle.append(row[6])
# In[8]:
##find the list index values of each automobile having a price rating of "med"
print(price_list)
price_list_med = []
print(len(price_list))
for i in range(len(price_list)):
print(i)
if price_list[i] == 'med':
price_list_med.append(i)
print(price_list_med)
# In[27]:
##find the "number of passengers" value for each auto having a "price" value of "med"
print(num_passenger_list)
print(len(num_passenger_list))
##using found indices in previous task to find the number of passengers with price of "med"
print(num_passenger_list[6],
num_passenger_list[16],
num_passenger_list[20],
num_passenger_list[23],
num_passenger_list[26],
num_passenger_list[29], )
# In[29]:
#making new list
num_pass_med = ["more", 2, 2, 2, 4, 2]
# In[30]:
#testing new list
print(num_pass_med)
# In[31]:
##Your fourth task is to
##find the index value for each automobile having a price value of "high"
##and a maintenance value that is not "low".
##Create a new list to store your findings and be sure to print your results.
# In[68]:
print(price_list)
print(main_cost_list)
####find the index value for each automobile having a price value of "high"
print(price_list)
price_list_high = []
print(len(price_list))
for i in range(len(price_list)):
print(i)
if price_list[i] == 'high':
price_list_high.append(i)
print(price_list_high)
##and a maintenance value that is not "low" trying to use same logic as previous function but this time using a not equals to
print(main_cost_list)
price_main_nlow = []
print(len(main_cost_list))
for i in range(len(main_cost_list)):
print(i)
if price_list[i] != 'low':
price_main_nlow.append(i)
print(price_main_nlow)
# In[70]:
#testing new lists
print(price_list_high)
print(price_main_nlow)
# In[71]:
##let's go that worked
# In[72]:
##Your fifth task is to
##find the index value for each auto having 2 doors and
##luggage value of "big".
##Create a new list to store your findings and be sure to print your results.
# In[73]:
#looking at list for each auto having two doors
print(num_doors_list)
# In[78]:
##finding indices of autos having two doors
two_door_cars = []
print(len(num_doors_list))
for i in range(len(num_doors_list)):
print(i)
if num_doors_list[i] == '2':
two_door_cars.append(i)
print(two_door_cars)
# In[81]:
##looking at luggage list
print(lugg_cap_list)
# In[82]:
##finding and print index values of luggage capacities that are 'big'
big_luggage = []
print(len(lugg_cap_list))
for i in range(len(lugg_cap_list)):
print(i)
if lugg_cap_list[i] == 'big':
big_luggage.append(i)
print(big_luggage)
# In[83]:
## these are the indices of the cars that have two doors AND have big luggage capacities
set(two_door_cars).intersection(big_luggage)
# In[84]:
#Finally, create a new list containing the only the integer equivalents of the doors values.
#Keep in mind that the lists you have created thus far are composed solely of strings.
#If you find any values of '5more' in your list, convert them to a '5'.
#After converting the '5more' values to '5', convert all of the items in your list
#to their numeric equivalent and calculate the average number of doors
#across all 35 autos using whichever of Python's built in functions you require.
#Print your result.##
# In[85]:
#looking at number of doors list
print(num_doors_list)
# In[89]:
print(num_doors_list)
# In[ ]: