Assing a key to two values

how can I assign a key to two values and then use functions to enter the key and modify one or both values?
More or less like a database
For example, I create this table using PrettyTable module:


Which approach should I take?
is like a TODO program but with two values and ID’s.

Steps:
ADD:

  1. User press “a” and write a “Scientific Name” and “Common Name”
    Then program assing an ID to that to values.

MODIFY:
2) user press “m” and program ask for the ID, user enters ID and program gives the option to change values of “Scientific Name” and then “Common Name”

DESTROY:
3) User enters ID and should be able to destroy a whole row of values.

Dictionaries can’t assing two values to one key.
So, what can I do?

What would be here a key, specifically? How that key would be used?

I would like an inmutable key, but if you have any other idea, it would be ok.
I was thinking in generate a random string with this

randomString = ‘’.join(random.choices(string.ascii_uppercase + string.digits, k=5))

With an ID would be easy modify, search and delete a complete row.

ADD:

  1. User press “a” and write a “Scientific Name” and “Common Name”
    Then program assing an ID to that to values.

MODIFY:
2) user press “m” and program ask for the ID, user enters ID and program gives the option to change values of “Scientific Name” and then “Common Name”

DESTROY:
3) User enters ID and should be able to destroy a whole row of values.

Why not use ID then?

I’m new on python, so, i don’t know wich methods are available to archive this. Can you send me a link, or something?

You have mentioned dictionary in the first post, do you have any ideas how to use that data type with the ID as key?

Nested dictionaries works perfectly well:

  {0: {'book': 'Wealth of Nations', 'author': 'Adam Smith'},
   1: {'book': 'Economic Sophisms',' author': 'Frédéric Bastiat'}}

Where 0 it’s the main key, “book” and “author” are the inner keys.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.