-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathveggies.py
More file actions
35 lines (23 loc) · 837 Bytes
/
veggies.py
File metadata and controls
35 lines (23 loc) · 837 Bytes
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
#In the loop, write the name of each vegetable and the color into a CSV called vegetables.csv
#The CSV should look like this:
#Bonus: add the length of the name of the vegtable as separate column
vegetables = [
{"name": "eggplant", "color": "purple"},
{"name": "tomato", "color": "red"},
{"name": "corn", "color": "yellow"},
{"name": "okra", "color": "green"},
{"name": "arugula", "color": "green"},
{"name": "broccoli", "color": "green"},
]
#Loops through each vegetable
#for veg in vegetables:
# print(veg)
#writes csvs to a file
import csv
with open('vegetables.csv', 'w') as f:
writer = csv.writer(f)
#write header row
writer.writerow(["item_name", "item_color"])
#Loops through each vegetable
for item in vegetables:
writer.writerow([item['name'], item['color']])