Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lists, fruits, books, forks, rope, gum
- 4, 2, 3, 0, 2, 2
- Manhattan Produce Market
- id, fruit, color
- 1, orange, orange
- 2, apple, red
- Books
- id, book, pages
- 1, Webster’s Dictionary, 1000
- 2, Tony the Towtruck, 20
- 3, The Twelfth Night, 144
- Rope
- id, rope, length, diameter, color
- 1, hemp, 12-feet, .5, green
- 2, sisal, 50-feet, .125, brown
- Kings County Candy
- id, flavor, color, big-league
- 1, grape, purple, yes
- 2, mega mango, yellow-orange, no
- import csv, re
- header = []
- table = []
- with open('toy.csv', 'r') as blob:
- reader = csv.reader(blob)
- curr = reader.__next__()
- while True:
- prev = curr
- try:
- curr = reader.__next__()
- except StopIteration:
- break
- if not ['id', ' book', ' pages'] == curr:
- continue
- else:
- header.append(prev)
- table.append(['title'] + curr)
- while True:
- try:
- curr = reader.__next__()
- if curr == []:
- break
- else:
- table.append(header[0] + curr)
- except StopIteration:
- break
- [['title', 'id', ' book', ' pages'],
- ['Books', '1', ' Webster’s Dictionary', ' 1000'],
- ['Books', '2', ' Tony the Towtruck', ' 20'],
- ['Books', '3', ' The Twelfth Night', ' 144']]
Add Comment
Please, Sign In to add comment