Convert dictionary to lists

Dear python experts ,
                              I am trying to do the following exrcise .. and am very new to python. Can somebody help me. I have a
Dictionary:
dictionary object like this{‘dodge’:’red’,’toyota’:’blue’,’nissan’:’green’ }.
I have to convert this to a list  like this

List object

[(‘dodge’,’red),(‘toyota,’blue’),(‘nissan ,’green’)  ]
 
and vice versa.
thanks a lot
testsubbu
TestsubbuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rjkimbleCommented:
The methods you're looking for are items() and dict(). For example:

>>> d = { 'dodge':'red', 'toyota':'blue','nissan':'green' }
>>> d.items( )
[('dodge', 'red'), ('nissan', 'green'), ('toyota', 'blue')]
>>> i = d.items( )
>>> dict( i )
{'dodge': 'red', 'nissan': 'green', 'toyota': 'blue'}

So if you have a dictionary, d, then dict( d.items( ) ) gives you an equivalent dictionary.
TestsubbuAuthor Commented:
I want to convert dictionary and store it in list like how i have mentioned in my comment.thanks for your help .. would youknow how do i do that
rjkimbleCommented:
I'm not sure I follow you. If d is a dictionary, then d.items( ) is a list of items in the form you're asking for. Am I missing something?
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

TestsubbuAuthor Commented:
Hmmm! i think i am getting what you mean .. however what i really require is
1. a function which accepts a dictionary and returns a list
2. a function which accepts a a list and returns a dictionary

thanks,
testsubbu
rjkimbleCommented:
1. You can do something like this:

def dict2list( d ):
    return d.items( )

2. The dict( ) function already does this. You could also do something like this:

def list2dict( l ):
    return dict( l )

Is that closer to what you want?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TestsubbuAuthor Commented:
Thanks a lot sir,
testsubbu
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.