troubleshooting Question

unable to Convert tuple or list into dictionary in python

Avatar of sam_2012
sam_2012 asked on
* python3Python
2 Comments1 Solution19 ViewsLast Modified:
Hi Team,

Iam getting the below error while iam creating thedictionary object , any help is really appreciated

Case 1 : Trying to create a tuple and using the tuple trying to create a dictionary
>>> t=(1,2),
>>> d=dict(t)
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    d=dict(t)
TypeError: cannot convert dictionary update sequence element #0 to a sequence

Case 2: Trying to create a list and using the list creating a dictionary
>>> l=[1,2,3,4]
>>> d=dict(l)
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    d=dict(l)
TypeError: cannot convert dictionary update sequence element #0 to a sequence
ASKER CERTIFIED SOLUTION
Louis LIETAER
System Infrastructure Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros