Sep-27-2018, 10:37 AM
Hello everybody,
I read data from an MySQL server and it gives me the info as a list dictionaries:
The result:
I want to put all this data in 1 dictionary with the heads: 'Name' and 'Id'
The dictionary looks like this:
Can somebody help me please
I read data from an MySQL server and it gives me the info as a list dictionaries:
1 2 3 4 5 6 |
db_ewon = con.cursor(dictionary = True ) db_ewon.execute( "SELECT Name,Id FROM esync_stations" ) df_ewon = db_ewon.fetchall() for x in df_ewon[ 0 : 5 ]: print (x) |
1 2 3 4 5 |
{ 'Name' : 'Station1' , 'Id' : 1 } { 'Name' : 'Station2' , 'Id' : 5 } { 'Name' : 'Station3' , 'Id' : 3 } { 'Name' : 'Station4' , 'Id' : 9 } { 'Name' : 'Station5' , 'Id' : 2 } |
The dictionary looks like this:
1 2 3 4 5 6 7 |
new_dict = { 'Station1' : 1 , 'Station2' : 5 , 'Station3' : 3 , 'Station4' : 9 , 'Station5' : 2 , } |