T
T
t1nsmer02022-04-10 04:55:05
MySQL
t1nsmer0, 2022-04-10 04:55:05

How to convert a list received from a database into a dictionary?

There is code:
6252389837109554633311.png
The code prints out a list retrieved from the database. How can such a list be converted to a dictionary? And is it even possible?
625238f1bb541248288052.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexNest, 2022-04-10
@AlexNest

Maybe.
It's not really clear what exactly you want to do.
If you turn each individual tuple, then write a function like this:

some_dict = {}
some_dict["letter"] = db_row[0] # db_row - кортеж
...
return some_dict

Then loop through and transform each element.
If you need to make a dictionary from the original list (I strongly doubt the usefulness and necessity of which), then it should be something like this:
some_dict  = {}
... # do cycle
some_dict[cha_index] = cha[cha_index] # cha_index - индекс значения в списке.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question