Skip to content
Advertisement

add multiple values to one key, but defaultdict only allows 2

In the CSV I’m reading from, there are multiple rows for each ID:

JavaScript

I need to extract each such that I will have one file per ID, with the timestamp, name, and text in that file. For example, for ID 444, it will have 2 timestamps and 2 different texts in it, along with the name.

I’m able to get the text designated to the proper ID, using this code:

JavaScript

The problem is that this isn’t enough, I need to add in the other values to the one ID key. If I try:

JavaScript

I get

JavaScript

Advertisement

Answer

Just use a list for value instead,

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement