Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6106883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:07:38+00:00 2026-05-23T14:07:38+00:00

I have a list that looks like: [(‘A’, 1), (‘B’, 2), (‘C’, 3)] I

  • 0

I have a list that looks like:

[('A', 1), ('B', 2), ('C', 3)]

I want to turn it into a dictionary that looks like:

{'A': 1, 'B': 2, 'C': 3}

What’s the best way to go about this?

EDIT: My list of tuples is actually more like:

[(A, 12937012397), (BERA, 2034927830), (CE, 2349057340)]

I am getting the error ValueError: dictionary update sequence element #0 has length 1916; 2 is required

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:07:39+00:00Added an answer on May 23, 2026 at 2:07 pm

    Your error:

    Why you are getting the ValueError: dictionary update sequence element #0 has length 1916; 2 is required error:

    The answer is that the elements of your list are not what you think they are. If you type myList[0] you will find that the first element of your list is not a two-tuple, e.g. ('A', 1), but rather a 1916-length iterable.

    Once you actually have a list in the form you stated in your original question (myList = [('A',1),('B',2),...]), all you need to do is dict(myList).


    [2021 edit: now also answers the actual question asked, not the intended question about the specific error:]

    In general:

    Either use the usual dict(iterableOrMapping) constructor, or use the dict comprehension {someExpr(k,v) for k:v in iterable} syntax:

    >>> example1 = [('A',1), ('B',2), ('C',3)]
    >>> dict(example1)
    {'A': 1, 'B': 2, 'C': 3}
    
    >>> {x:x**2 for x in range(3)}
    {0: 0, 1: 1, 2:4}
    
    # inline; same as example 1 effectively. may be an iterable, such as
    # a sequence, evaluated generator, generator expression
    
    >>> dict( zip(range(2),range(2)) )
    {0: 0, 1: 1, 2:2}
    

    A Python dictionary is an O(1)-searchable unordered collection of pairs {(key→value), …} where keys are any immutable objects and values are any object.

    Keys MUST implement the .__eq__()
    and .__hash__() methods to be usable in the dictionary. If you are thinking of implementing this, you are likely doing something wrong and should maybe consider a different mapping data structure! (Though sometimes you can get away with wrapping the keys in a different wrapper structure and using a regular dict, this may not be ideal.)

    Intermediate or advanced programmers who wish to implement a ‘frozen’ or ‘immutable’ type, or one which masquerades as one, must be very careful of implications or else your program will be wrong with extremely subtle and near-impossible-to-find bugs:

    You can’t use a dict if you allow yourself to mutate the object later such that its notion of equality might change. Objects considered equal must always have __eq__ return True and have __hash__ return identical values.

    The methods must exactly obey the spec. This means that:

    • For novices: Hash functions(wikip.) let you get a false-positive or true-positive result; hash(x)==hash(y) means x MIGHT equal y and the internal python code must then check x==y (.__eq__) to confirm it’s a true-positive and not a false-positive. This allows O(1) lookup.
    • For novices: It is critically important that the __hash__ value not change for any reason once the object is in its final state. If you cannot guarantee both this and hash(x)!=hash(y) implies x!=y, you should not be using a dict.
    • One might consider a different type of mapping rather than modifying the data itself. This can be equivalent to writing a wrapper object, at the cost of using a library. This is usually not necessary.
    • For experts: It should also be noted that the hashes of some default objects are salted and may change between python invocations and versions (this may be a gotcha if you store or network-communicate data in any way that contains python hashes; they are an internal detail that should be regenerated on each process startup).

    Python has a bunch of built-in frozen datastructures such as namedtuple, frozenset, etc., but they are sometimes harder to work with. tuple is the basic frozen variant of the basic list structure (which would let you store a {(1, 2): 3, (4, 5): 6}). It also has some variants of the dict structure. If you want to get a map from "frozen dicts" to values, frozendict doesn’t exist except as a third-party library, but you can extract the dict’s .items() as a an unordered frozenset of tuples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a list of lists that looks like this: dupe = [['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c',
I have a list of lists that looks like this: x[[state]][[year]] . Each element
I have a binary tree in unordered list that looks like this: <ul> <li>1
I have a file that contain list of numbers that looks like this: 10^-92
I have code that looks like this: template<class T> class list { public: class
I have a query that looks like this: it takes a list of IDs
I have a structure that roughly looks like this: List<ProductLine> -> ID Name ...
I have code that I want to look like this: List<Type> Os; ... foreach
Say I have a list that looks like this: ['item1', 'item2', 'item3', 'item4', 'item5',
Let's say I have a list that looks like this: <ul> <li id=q></li> <li

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.