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

                      How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                      해남서초등학교 학교 연혁 학교 동문 외부 링크 둘러보기 메뉴북위 34° 34′ 21″ 동경 126° 35′ 50″ / 북위 34.5726385° 동경 126.5972670°  / 34.5726385; 126.5972670해남서초등학교eh