Solved

Create a dictionary from a list in python

Posted on 2015-02-09
3
161 Views
Last Modified: 2015-02-09
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
Comment
Question by:DrDamnit
3 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40598024
Hi,

pls try

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

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

Print Res

Regards
0
 
LVL 37

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40598040
listA = ['a','b','c']
dictB = {}
for a in listA:
  dictB[a] =None

dictB
0
 
LVL 32

Author Comment

by:DrDamnit
ID: 40598589
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question