Skip to content
Advertisement

Representing a creation of list and dictionary using comprehensions in python

I have some questions related to the program I wrote. The data I have is following

JavaScript

To convert into a specific dictionary based on the number of columns provided, I use the strategy to write 2 functions. The first function is converting into a 2-dimensional list where 1st item of the 2d list provides the column names while other items representing values. The second function gives the expected output by mapping the key and values based on the position where it is situated

JavaScript

The following is my code

JavaScript

Although I got the expected output, is there any way to represent those functions using comprehension, and if no then , is there any optimized way to get the same output?

Thanks

Advertisement

Answer

you can use list comprehension

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