Regarding Value error

Hi All,

I am getting the below error, i tried , but i am unable to find what is the error, how to rectify it. can someone please explain me the error.

ValueError Traceback (most recent call last)
----> 1 person = dict("{}is aged {}, and owns an {}.". format(
2 person [“name”],
3 person [“age”],
4 “Android phone” if person [“has_android_phone”] else “iphone”
5 ))

ValueError: dictionary update sequence element #0 has length 1; 2 is required

Note : i have already defined the dictionary in the previous cell

This is not going to be the help you might have wanted.
When I started this problem I too tried to “show off” and use the dict() function.
Probably got the same error.
So instead of trying to create a dictionary I just assigned person to a dictionary object.

person = {"key1": value1, "key2": value2, "key3": value3}

use the curly braces {} and just assign a dictionary object instead of translating a tuple or list or just a bunch of stuff thrown.
btw you did not assign a dictionary in the previous cell, you are trying to assign a dictionary in this cell and that is where your Error message is getting generated. ’ … has length 1; 2 is required’ because there is no “:” (the colon) A colon is required to separate a dictionary key from a dictionary value

@sidujjain explains it better
You’re not missing a colon, the error thrown says it expects two things and only got one. The two things being a key and a value for each item in the dictionary.

@cvulaganathan you are passing string in dict constructor. Instead you should be passing key - value pairs. e.g. dict(brand="Ford", model="Mustang", year=1964)

1 Like