0
$\begingroup$

I've this Python code that allows me to collect data from Todoist API. Now I want to store this data into a Dictionary in order to make some data processing and some advanced analytics. Using this code how can I store this values into the structure ?

from pytodoist import todoist
user = todoist.login('####','""""')
projects = user.get_projects()
for project in projects:
    print(project.name)

tasks = user.get_tasks()
for task in tasks:
    print("Project: ", task.project.name, ", Task: ", task.content, ", Date: ", task.date_string, ", Priority: ", task.priority, ", Added in: ", task.date_added)

My key_pais: The strings that I've in For loop "Project", "Task", etc. Values: the values from taks

Many thanks!

$\endgroup$
  • $\begingroup$ Can you be more specific as to what's the key and value pairs for your task? $\endgroup$ – Aditya Mar 27 '18 at 10:52
  • $\begingroup$ @Aditya thanks! I add some more information in question $\endgroup$ – John_Rodgers Mar 27 '18 at 11:02
  • $\begingroup$ It would be better we if you will convert it to a JSON object as JSON is in short dictionary with multiple levels $\endgroup$ – Aditya Mar 27 '18 at 12:32
  • $\begingroup$ Like this: stackoverflow.com/questions/27102573/… ??? $\endgroup$ – John_Rodgers Mar 27 '18 at 15:06
  • $\begingroup$ Yes that will do but change it to suite your desires.. $\endgroup$ – Aditya Mar 27 '18 at 16:15
0
$\begingroup$

At first remember that a dictionary is just bunches of keys and value pairs...

So, if the key is $a$ and the value is $10$ , you can access the value by doing d[a] (d is the dictionary)

Beaware that there is no order to storing the values, you can use OrderedDict for that..

Also you can have two values for the same key in a simple dictionary.

Here's the complete answer

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.