How to convert list of list to dictionary in Python?

Seetha Raman

I have the following list of list:

website=[["Ram"],["google"],["yahoo"],["linkedin"],["facebook"],["twitter"],  
    ["google"],["yahoo"],["linkedin"],["facebook"],["twitter"],["google"],["yahoo"],
    ["linkedin"]]

i would like to get the output like:

webdict={"Ram":1,"google":3,"yahoo":3,"linkedin":3,"facebook":2,"twitter":2}
Remy J
website=[["Ram"],["google"],["yahoo"],["linkedin"],["facebook"],["twitter"],["google"],["yahoo"],["linkedin"],["facebook"],["twitter"],["google"],["yahoo"],["linkedin"]]

print dict([(i[0], website.count(i)) for i in website])

The output :

{'google': 3, 'twitter': 2, 'Ram': 1, 'yahoo': 3, 'linkedin': 3, 'facebook': 2}

To find out more about lists see the doc

  • Section "5.1.4. List Comprehensions" will explain the for statement.
  • Section "5.1. More on Lists" will explain the website.count(i)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

python dictionary and list: how to convert it?

how to convert a list to dictionary in python?

How to convert list to dictionary in Python?

How to convert list of string to list of dictionary in Python

How to convert python list to python dictionary with sequence

Convert a dictionary to a list - Python

Convert a list to a dictionary in Python

python convert list to dictionary

How to convert list of list to dictionary

How to convert list to dictionary

How to convert dictionary list?

How to convert this list into a dictionary

How to convert list into dictionary

How to convert a list of tuples to a dictionary of dictionaries in Python?

How do I convert list into dictionary in Python?

How to convert unciode to list of dictionary in python

How to convert String values in a dictionary to a list in python?

How to convert list of string to dictionary in python

Python 3 - How to convert a string to a list of dictionary

How to convert dictionary list to custom objects in Python

How to convert list to dictionary in python with key value?

how to convert list of dictionary into string python

How convert list of dictionaries to a dictionary of dictionaries in Python

how to convert 2 dimensional list into list of dictionary in python?

Convert python dictionary to python list

How to convert dictionary to pandas DataFrame in Python when dictionary value is a List?

How to convert every dictionary in a list to a nested dictionary in python?

Python: Convert list to dictionary with indexes

Convert a List of into a dictionary in Python 3.8