How do I unpack the values of a tuple in a dictionary comprehension without creating any new variables? [duplicate]python tuple to dictHow do I sort a list of dictionaries by a value of the dictionary?How to return multiple values from a function?How do you get the logical xor of two variables in Python?How do I determine the size of an object in Python?Convert bytes to a string?How do I sort a dictionary by value?Proper way to declare custom exceptions in modern Python?Create a dictionary with list comprehension in PythonHow to access environment variable values?Python Dictionary Comprehension

Loading Latex packages into Mathematica

Can a tourist shoot a gun in the USA?

Where to find every-day healthy food near Heathrow Airport?

What are the implications of the new alleged key recovery attack preprint on SIMON?

German characters on US-International keyboard layout

Why is it harder to turn a motor/generator with shorted terminals?

What information do scammers need to withdraw money from an account?

Does SQL Server allow (make visible) DDL inside a transaction to the transaction prior to commit?

51% attack - apparently very easy? refering to CZ's "rollback btc chain" - How to make sure such corruptible scenario can never happen so easily?

Was this character’s old age look CGI or make-up?

LWC1513: @salesforce/resourceUrl modules only support default imports

Non-deterministic Finite Automata | Sipser Example 1.16

Is there any good reason to write "it is easy to see"?

Frame adjustment for engine

what does a native speaker say when he wanted to leave his work?

As programers say: Strive to be lazy

Extracting sublists that contain similar elements

Formal Definition of Dot Product

How exactly does artificial gravity work?

Rounding a number extracted by jq to limit the decimal points

Tikzpicture in figure problem

Can I say: "When was your train leaving?" if the train leaves in the future?

Is taking modulus on both sides of an equation valid?

How does emacs `shell-mode` know to prompt for sudo?



How do I unpack the values of a tuple in a dictionary comprehension without creating any new variables? [duplicate]


python tuple to dictHow do I sort a list of dictionaries by a value of the dictionary?How to return multiple values from a function?How do you get the logical xor of two variables in Python?How do I determine the size of an object in Python?Convert bytes to a string?How do I sort a dictionary by value?Proper way to declare custom exceptions in modern Python?Create a dictionary with list comprehension in PythonHow to access environment variable values?Python Dictionary Comprehension






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








1
















This question already has an answer here:



  • python tuple to dict

    6 answers



I have a tuple that contains multiple sub tuples, with a fixed length of two and each sub tuple has two string values.



NOTE: The length and value type of these sub tuples never change.



I'd like to use the sub tuples in a dictionary-comprehension, like this:



sub_tuple for sub_tuple in main_tuple


The problem is, I get:



(w, x), (y, z)


Instead of:



w: x, y: z


How can I get this to work without creating any additional variables?



For example, how do I avoid doing something like this:



x = 
for sub_tuple in main_tuple:
x[sub_tuple[0]] = sub_tuple[1]
# do whatever with x...









share|improve this question















marked as duplicate by Patrick Artner python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 23 at 13:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • The dupe "reverses" the order - but you should be able to derive your solution from it as well. Those answers duplicate the ones give here "with an added twist".

    – Patrick Artner
    Mar 23 at 13:29

















1
















This question already has an answer here:



  • python tuple to dict

    6 answers



I have a tuple that contains multiple sub tuples, with a fixed length of two and each sub tuple has two string values.



NOTE: The length and value type of these sub tuples never change.



I'd like to use the sub tuples in a dictionary-comprehension, like this:



sub_tuple for sub_tuple in main_tuple


The problem is, I get:



(w, x), (y, z)


Instead of:



w: x, y: z


How can I get this to work without creating any additional variables?



For example, how do I avoid doing something like this:



x = 
for sub_tuple in main_tuple:
x[sub_tuple[0]] = sub_tuple[1]
# do whatever with x...









share|improve this question















marked as duplicate by Patrick Artner python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 23 at 13:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • The dupe "reverses" the order - but you should be able to derive your solution from it as well. Those answers duplicate the ones give here "with an added twist".

    – Patrick Artner
    Mar 23 at 13:29













1












1








1









This question already has an answer here:



  • python tuple to dict

    6 answers



I have a tuple that contains multiple sub tuples, with a fixed length of two and each sub tuple has two string values.



NOTE: The length and value type of these sub tuples never change.



I'd like to use the sub tuples in a dictionary-comprehension, like this:



sub_tuple for sub_tuple in main_tuple


The problem is, I get:



(w, x), (y, z)


Instead of:



w: x, y: z


How can I get this to work without creating any additional variables?



For example, how do I avoid doing something like this:



x = 
for sub_tuple in main_tuple:
x[sub_tuple[0]] = sub_tuple[1]
# do whatever with x...









share|improve this question

















This question already has an answer here:



  • python tuple to dict

    6 answers



I have a tuple that contains multiple sub tuples, with a fixed length of two and each sub tuple has two string values.



NOTE: The length and value type of these sub tuples never change.



I'd like to use the sub tuples in a dictionary-comprehension, like this:



sub_tuple for sub_tuple in main_tuple


The problem is, I get:



(w, x), (y, z)


Instead of:



w: x, y: z


How can I get this to work without creating any additional variables?



For example, how do I avoid doing something like this:



x = 
for sub_tuple in main_tuple:
x[sub_tuple[0]] = sub_tuple[1]
# do whatever with x...




This question already has an answer here:



  • python tuple to dict

    6 answers







python python-3.x dictionary tuples dictionary-comprehension






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 22 at 11:07









piet.t

10.2k73246




10.2k73246










asked Mar 23 at 13:19









LogicalBranchLogicalBranch

1,9001637




1,9001637




marked as duplicate by Patrick Artner python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 23 at 13:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Patrick Artner python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 23 at 13:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • The dupe "reverses" the order - but you should be able to derive your solution from it as well. Those answers duplicate the ones give here "with an added twist".

    – Patrick Artner
    Mar 23 at 13:29

















  • The dupe "reverses" the order - but you should be able to derive your solution from it as well. Those answers duplicate the ones give here "with an added twist".

    – Patrick Artner
    Mar 23 at 13:29
















The dupe "reverses" the order - but you should be able to derive your solution from it as well. Those answers duplicate the ones give here "with an added twist".

– Patrick Artner
Mar 23 at 13:29





The dupe "reverses" the order - but you should be able to derive your solution from it as well. Those answers duplicate the ones give here "with an added twist".

– Patrick Artner
Mar 23 at 13:29












2 Answers
2






active

oldest

votes


















3














You should be able to do:



x = 
key: value
for key, value in main_tuple



Even simpler, you could do x = dict(main_tuple)






share|improve this answer






























    3














    You can use the dict constructor instead:



    dict(main_tuple)





    share|improve this answer





























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      You should be able to do:



      x = 
      key: value
      for key, value in main_tuple



      Even simpler, you could do x = dict(main_tuple)






      share|improve this answer



























        3














        You should be able to do:



        x = 
        key: value
        for key, value in main_tuple



        Even simpler, you could do x = dict(main_tuple)






        share|improve this answer

























          3












          3








          3







          You should be able to do:



          x = 
          key: value
          for key, value in main_tuple



          Even simpler, you could do x = dict(main_tuple)






          share|improve this answer













          You should be able to do:



          x = 
          key: value
          for key, value in main_tuple



          Even simpler, you could do x = dict(main_tuple)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 13:21









          schillingtschillingt

          6,30511824




          6,30511824























              3














              You can use the dict constructor instead:



              dict(main_tuple)





              share|improve this answer



























                3














                You can use the dict constructor instead:



                dict(main_tuple)





                share|improve this answer

























                  3












                  3








                  3







                  You can use the dict constructor instead:



                  dict(main_tuple)





                  share|improve this answer













                  You can use the dict constructor instead:



                  dict(main_tuple)






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 23 at 13:22









                  blhsingblhsing

                  46.4k51747




                  46.4k51747













                      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