0

I have the following code snippet where am assigning values to dictionary..currently the dictionary values are getting printed as normal values..i want to them to convert to a list,how do i change the "database[data]=value" line to achieve this?

database={} ....... database[data]=value //assigning value to a dictionary print database ............... Expected output:- internal_dep = {'313115': ['313113'],'213114': ['213103'] } Current output:- internal_dep = {'313115': '313113','213114': '213103' } 

Thanks

1
  • Your question is hard to understand. The answerers have interpreted it in at least 2 different ways. Commented Apr 28, 2013 at 6:24

2 Answers 2

2

you can try:

database[data]=[value] 

If you only want to print it this way, you can try:

print({k:[v] for k, v in database.items()}) 
Sign up to request clarification or add additional context in comments.

Comments

0

A list cannot (easily) be used as a dictionary in Python—although Lisp does represent dictionaries this way. However, you can get at either the values or the keys and convert them to a list like so:

print list(database.values()) 

or

print list(database.keys()) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.