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

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현