-1

So basically I'm at a wall with an assignment and it's beginning to really frustrate me. Essentially I have a CSV file and my goal is to count how an the amount of times a string is called. So like column 1 would have a string and column 2 would have a integer connected to it. I ultimately need this to be formatted into a dictionary. Where I am stuck is how the heck do I do this without using imported libraries. I am only allowed to iterate through the file using for loops. Would my best bet be indexing each line and creating that into a string and count how many times that string is called? Any insight would be appreciated.

fame346
  • 19
  • 3
  • Possible duplicate of [Creating a dictionary from a csv file?](https://stackoverflow.com/questions/6740918/creating-a-dictionary-from-a-csv-file) – felixwege Nov 05 '19 at 00:51

1 Answers1

0

If you don't want to you any library (and assuming you are using python) you can use a dict comprehension, like this:

with open("data.csv") as file:
    csv_as_dict = {line[0]: line[1] for line in file.readlines()}

Note: The question is possibly a duplicate of Creating a dictionary from a csv file?.

felixwege
  • 121
  • 1
  • 6