Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

Create a dictionary from a list in python

I have a list:
['a','b','c']

Open in new window


I would like to turn it into a dictionary that looks like this:
{
	'a':None,
	'b':None,
	'c':none
}

Open in new window


I think this can be accomplished with map(), but not seeing how to do it.
0
DrDamnit
Asked:
DrDamnit
1 Solution
 
Rgonzo1971Commented:
Hi,

pls try

a =['a','b','c']

Res = dict((k,None) for k in a)

Print Res

Regards
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
listA = ['a','b','c']
dictB = {}
for a in listA:
  dictB[a] =None

dictB
0
 
DrDamnitAuthor Commented:
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now