Python Forum
PyMySQL return a single dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyMySQL return a single dictionary
#1
Hello,

I'm using pymysql to get all the contents of a table with two columns - user_id and user_name (user_id is the primary key).

is there a way to return a single dictionary with user_id's as keys and user_names as values?
Reply
#2
pass what you get (list/generator of tuples) to dict() function
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pymysql can't do SELECT * Pedroski55 3 553 Sep-11-2021, 10:18 PM
Last Post: Pedroski55
  convert List with dictionaries to a single dictionary iamaghost 3 1,106 Jan-22-2021, 03:56 PM
Last Post: iamaghost
  pymysql won't handle some diacritic characters awarren2001AD 0 575 Apr-16-2020, 08:58 AM
Last Post: awarren2001AD
  pyMySQL - ROW_NUMBER in SQL statement JayCee 1 1,112 Apr-12-2020, 08:40 PM
Last Post: JayCee
  pyMySQL How do I get the row id JayCee 3 1,299 Apr-12-2020, 08:38 PM
Last Post: JayCee
  Search a List of Dictionaries by Key-Value Pair; Return Dictionary/ies Containing KV dn237 19 3,605 May-29-2019, 02:27 AM
Last Post: heiner55
  How to take a single value from dictionary ginjaninja247 1 936 May-28-2019, 12:34 PM
Last Post: buran
  pymysql: formating ouput of query wardancer84 18 4,830 Oct-04-2018, 01:54 PM
Last Post: wardancer84
  pymysql ifnull aland 4 2,337 Sep-06-2018, 05:58 AM
Last Post: buran
  Return JSON records in single line using python 2.7 anandmn85 0 1,705 May-14-2018, 09:16 AM
Last Post: anandmn85

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020