Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dictionaries
#2
dict comprehension:
new_dict = {item['Name']:item['Id'] for item in df_ewon[0:5]}
note you can also iterate over cursor as iterator - https://dev.mysql.com/doc/connector-pyth...chone.html
example from the docs
# Using the cursor as iterator
cursor.execute("SELECT * FROM employees")
for row in cursor:
  print(row)
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


Messages In This Thread
dictionaries - by brecht83 - Sep-27-2018, 10:37 AM
RE: dictionaries - by buran - Sep-27-2018, 11:05 AM
RE: dictionaries - by gruntfutuk - Sep-27-2018, 11:12 AM

Forum Jump:

User Panel Messages

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