Skip to content
Advertisement

Create a dictionary using a foor-loop and add a label for each in python

I have the following data, however I want to create a dictionary using a foor loop.

JavaScript

Is it possible to do that?

I need a dictionary with this structure:

JavaScript

Comment 1, Comment 2 and so on are arbitrary labels that I am assigning and are not mentioned in my dataset.

Advertisement

Answer

A simple way to write this down:

JavaScript

This will get the expected output for all tuples in the dictionary, “print” can be switched to return if needed.

Another approach:

JavaScript

These may solve the issue.

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