Do I need to use `@` or a `,` for the delimiter?

new to code, was having trouble iterating through the proper dictionary, here’s my final solution:

import csv

with open('books.csv') as books_csv:
  books_reader = csv.DictReader(books_csv, delimiter='@')
  isbn_list = []
  for book in books_reader:
    isbn_list.append(book['ISBN'])
3 Likes

Instead of using a list comprehension, I use a for loop, too! But did you run this out? I couldn’t. And I tried the answer, it couldn’t run out either.

1 Like

Add a print statement at the end to print out the isbn_list object. You should get this output…

['978-0-12-995015-8', 
'978-1-78110-100-1', 
'978-0-315-25137-3', 
'978-0-388-70665-7', 
'978-1-75098-721-6', 
'978-1-06-483628-6', 
'978-0-7419-8114-1', 
'978-1-4457-0480-7', 
'978-0-657-61030-2', 
'978-1-5039-7539-2']

The code sample above is what I have used and it passed back when I did this lesson.

list comprehension
import csv
with open('books.csv') as books_csv:
  books_reader = csv.DictReader(books_csv, delimiter='@')
  isbn_list = [book['ISBN'] for book in books_reader]
print (isbn_list)
1 Like

Hi mtf,

I have a question, you have got in your output as separed lines like this:
[‘978-0-12-995015-8’,
‘978-1-78110-100-1’,
‘978-0-315-25137-3’,
‘978-0-388-70665-7’,…
]
my questions is, why I’ve got in one single line?
[‘978-0-12-995015-8’, ‘978-1-78110-100-1’, ‘978-0-315-25137-3’, ‘978-0-388-70665-7’,…]

Thanks for you help.

Whitespace is optional, and largely ignored if the syntax is correct.

[
    value,
    value,
    value,
    value
]

is easier to read than a single line. Either form is valid.

I ran into the same issue. The problem is the instructions say to use @ as the delimiter but the actual CSV file is delimited by commas. I used to code below to take a look at the CSV and that’s how I figured it out.

print(books_csv.reader())

I copy and pasted the results from the lesson here:

Author,ISBN,Title
Lauren Murray,978-0-12-995015-8,"Enviornment Call, Amount Later Page Country"
Micheal Jones,978-1-78110-100-1,Rate Security Full
Alexander Carr,978-0-315-25137-3,Still Response Size
Michael Williams,978-0-388-70665-7,Position Result Five
Kathleen Ferguson,978-1-75098-721-6,Country Week Receive And Sign
Sarah Dorsey,978-1-06-483628-6,Audience Truth Small
Mary Middleton,978-0-7419-8114-1,Travel: Special Offer Near Allow Goal
William Todd,978-1-4457-0480-7,Money Exactly Drop Teach
Joan Martin,978-0-657-61030-2,Theory Do Half Change
Gary Roman,978-1-5039-7539-2,Bill Serve Pull Industry South Job

getting ERROR all the time till I change the delimiter to ‘,’