Convert a list to dictionary without extra curly brackets being addedHow do I merge a list of dicts into a single dict?How do you sort a dictionary by value?How do I sort a list of dictionaries by a value of the dictionary?Convert two lists into a dictionary in PythonPython creating a dictionary of listsConvert a String representation of a Dictionary to a dictionary?Create a dictionary with list comprehension in PythonUse of *args and **kwargsConvert a list to a dictionary in PythonPython Dictionary ComprehensionHow to return dictionary keys as a list in Python?

USPS Back Room - Trespassing?

Creating second map without labels using QGIS?

Dad jokes are fun

Why did Jon Snow admit his fault in S08E06?

Is keeping the forking link on a true fork necessary (Github/GPL)?

What is the use case for non-breathable waterproof pants?

Why is this integration method not valid?

Why does splatting create a tuple on the rhs but a list on the lhs?

Expected maximum number of unpaired socks

How was Daenerys able to legitimise Gendry?

Is this homebrew "Cactus Grenade" cantrip balanced?

The disk image is 497GB smaller than the target device

Count all vowels in string

Can a ring of spell storing and access to Find spells produce an endless menagerie?

Why did it take so long for Germany to allow electric scooters / e-rollers on the roads?

Freedom of Speech and Assembly in China

What did the 'turbo' button actually do?

Navigating a quick return to previous employer

How to melt snow without fire or using body heat?

Using too much dialogue?

Is it legal to have an abortion in another state or abroad?

What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?

Do copyright notices need to be placed at the beginning of a file?

How to keep consistency across the application architecture as a team grows?



Convert a list to dictionary without extra curly brackets being added


How do I merge a list of dicts into a single dict?How do you sort a dictionary by value?How do I sort a list of dictionaries by a value of the dictionary?Convert two lists into a dictionary in PythonPython creating a dictionary of listsConvert a String representation of a Dictionary to a dictionary?Create a dictionary with list comprehension in PythonUse of *args and **kwargsConvert a list to a dictionary in PythonPython Dictionary ComprehensionHow to return dictionary keys as a list in Python?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Say I have a list like this:



alist = ['key': 'value']


And then I convert it to a dictionary like this



adict = dict(alist)


The formatting becomes



'''key: 'value'


This makes it so I can't access the data from the dictionary. Is there a way to convert the list to a dictionary without there being extra ' ' -- brackets and single quotes










share|improve this question



















  • 1





    The code you posted does not run without exceptions. It does not produce the output you posted. Please check again.

    – Markus Unterwaditzer
    Mar 23 at 23:41











  • Possible duplicate of How do I merge a list of dicts into a single dict?

    – Michael Doubez
    Mar 23 at 23:45











  • adict = alist[0] should do it.

    – martineau
    Mar 24 at 2:18

















0















Say I have a list like this:



alist = ['key': 'value']


And then I convert it to a dictionary like this



adict = dict(alist)


The formatting becomes



'''key: 'value'


This makes it so I can't access the data from the dictionary. Is there a way to convert the list to a dictionary without there being extra ' ' -- brackets and single quotes










share|improve this question



















  • 1





    The code you posted does not run without exceptions. It does not produce the output you posted. Please check again.

    – Markus Unterwaditzer
    Mar 23 at 23:41











  • Possible duplicate of How do I merge a list of dicts into a single dict?

    – Michael Doubez
    Mar 23 at 23:45











  • adict = alist[0] should do it.

    – martineau
    Mar 24 at 2:18













0












0








0








Say I have a list like this:



alist = ['key': 'value']


And then I convert it to a dictionary like this



adict = dict(alist)


The formatting becomes



'''key: 'value'


This makes it so I can't access the data from the dictionary. Is there a way to convert the list to a dictionary without there being extra ' ' -- brackets and single quotes










share|improve this question
















Say I have a list like this:



alist = ['key': 'value']


And then I convert it to a dictionary like this



adict = dict(alist)


The formatting becomes



'''key: 'value'


This makes it so I can't access the data from the dictionary. Is there a way to convert the list to a dictionary without there being extra ' ' -- brackets and single quotes







python dictionary






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 2:18









martineau

71.7k1093190




71.7k1093190










asked Mar 23 at 23:35









the_martianthe_martian

352216




352216







  • 1





    The code you posted does not run without exceptions. It does not produce the output you posted. Please check again.

    – Markus Unterwaditzer
    Mar 23 at 23:41











  • Possible duplicate of How do I merge a list of dicts into a single dict?

    – Michael Doubez
    Mar 23 at 23:45











  • adict = alist[0] should do it.

    – martineau
    Mar 24 at 2:18












  • 1





    The code you posted does not run without exceptions. It does not produce the output you posted. Please check again.

    – Markus Unterwaditzer
    Mar 23 at 23:41











  • Possible duplicate of How do I merge a list of dicts into a single dict?

    – Michael Doubez
    Mar 23 at 23:45











  • adict = alist[0] should do it.

    – martineau
    Mar 24 at 2:18







1




1





The code you posted does not run without exceptions. It does not produce the output you posted. Please check again.

– Markus Unterwaditzer
Mar 23 at 23:41





The code you posted does not run without exceptions. It does not produce the output you posted. Please check again.

– Markus Unterwaditzer
Mar 23 at 23:41













Possible duplicate of How do I merge a list of dicts into a single dict?

– Michael Doubez
Mar 23 at 23:45





Possible duplicate of How do I merge a list of dicts into a single dict?

– Michael Doubez
Mar 23 at 23:45













adict = alist[0] should do it.

– martineau
Mar 24 at 2:18





adict = alist[0] should do it.

– martineau
Mar 24 at 2:18












3 Answers
3






active

oldest

votes


















1














You can use the index 0 to avoid the extra braces because the dictionary can be accessed as alist[0]. Moreover, you do not need dict additionally because your list content is already a dictionary



adict = alist[0]


Now you get the desired behavior



print (adict)
# 'key': 'value'





share|improve this answer

























  • @DeveshKumarSingh: It works for me. Anyway, dict is not need here because the list contains already a dictionary. Check my edit

    – Sheldore
    Mar 23 at 23:41


















1














If you first structure your list by swapping the curly braces, you won't have any issues using this :)



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






share|improve this answer






























    0














    If your objective is to initialise a dictionary object with a key value pair (or a bunch of key value pairs), why would you use a list first?



    You could simple write



    adict = 'key': 'value', 'Hello': 'world' 

    print(adict)






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319366%2fconvert-a-list-to-dictionary-without-extra-curly-brackets-being-added%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      You can use the index 0 to avoid the extra braces because the dictionary can be accessed as alist[0]. Moreover, you do not need dict additionally because your list content is already a dictionary



      adict = alist[0]


      Now you get the desired behavior



      print (adict)
      # 'key': 'value'





      share|improve this answer

























      • @DeveshKumarSingh: It works for me. Anyway, dict is not need here because the list contains already a dictionary. Check my edit

        – Sheldore
        Mar 23 at 23:41















      1














      You can use the index 0 to avoid the extra braces because the dictionary can be accessed as alist[0]. Moreover, you do not need dict additionally because your list content is already a dictionary



      adict = alist[0]


      Now you get the desired behavior



      print (adict)
      # 'key': 'value'





      share|improve this answer

























      • @DeveshKumarSingh: It works for me. Anyway, dict is not need here because the list contains already a dictionary. Check my edit

        – Sheldore
        Mar 23 at 23:41













      1












      1








      1







      You can use the index 0 to avoid the extra braces because the dictionary can be accessed as alist[0]. Moreover, you do not need dict additionally because your list content is already a dictionary



      adict = alist[0]


      Now you get the desired behavior



      print (adict)
      # 'key': 'value'





      share|improve this answer















      You can use the index 0 to avoid the extra braces because the dictionary can be accessed as alist[0]. Moreover, you do not need dict additionally because your list content is already a dictionary



      adict = alist[0]


      Now you get the desired behavior



      print (adict)
      # 'key': 'value'






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Mar 23 at 23:39

























      answered Mar 23 at 23:37









      SheldoreSheldore

      17.4k31330




      17.4k31330












      • @DeveshKumarSingh: It works for me. Anyway, dict is not need here because the list contains already a dictionary. Check my edit

        – Sheldore
        Mar 23 at 23:41

















      • @DeveshKumarSingh: It works for me. Anyway, dict is not need here because the list contains already a dictionary. Check my edit

        – Sheldore
        Mar 23 at 23:41
















      @DeveshKumarSingh: It works for me. Anyway, dict is not need here because the list contains already a dictionary. Check my edit

      – Sheldore
      Mar 23 at 23:41





      @DeveshKumarSingh: It works for me. Anyway, dict is not need here because the list contains already a dictionary. Check my edit

      – Sheldore
      Mar 23 at 23:41













      1














      If you first structure your list by swapping the curly braces, you won't have any issues using this :)



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






      share|improve this answer



























        1














        If you first structure your list by swapping the curly braces, you won't have any issues using this :)



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






        share|improve this answer

























          1












          1








          1







          If you first structure your list by swapping the curly braces, you won't have any issues using this :)



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






          share|improve this answer













          If you first structure your list by swapping the curly braces, you won't have any issues using this :)



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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 23:40









          David SilveiroDavid Silveiro

          595518




          595518





















              0














              If your objective is to initialise a dictionary object with a key value pair (or a bunch of key value pairs), why would you use a list first?



              You could simple write



              adict = 'key': 'value', 'Hello': 'world' 

              print(adict)






              share|improve this answer



























                0














                If your objective is to initialise a dictionary object with a key value pair (or a bunch of key value pairs), why would you use a list first?



                You could simple write



                adict = 'key': 'value', 'Hello': 'world' 

                print(adict)






                share|improve this answer

























                  0












                  0








                  0







                  If your objective is to initialise a dictionary object with a key value pair (or a bunch of key value pairs), why would you use a list first?



                  You could simple write



                  adict = 'key': 'value', 'Hello': 'world' 

                  print(adict)






                  share|improve this answer













                  If your objective is to initialise a dictionary object with a key value pair (or a bunch of key value pairs), why would you use a list first?



                  You could simple write



                  adict = 'key': 'value', 'Hello': 'world' 

                  print(adict)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 23 at 23:43









                  GroGro

                  50549




                  50549



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319366%2fconvert-a-list-to-dictionary-without-extra-curly-brackets-being-added%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript