Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create a dictionary from a list in python

Posted on 2015-02-09
3
Medium Priority
?
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

Accepted Solution

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

pls try

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

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

Print Res

Regards
0
 
LVL 38

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

715 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