[Python] indexing lists in python

Discussão em 'Python' iniciado por Stack, Setembro 26, 2024.

  1. Stack

    Stack Membro Participativo

    I need to create a list in python to gather diverse information about a large number of people (name, date of birth, ID number, e-mail address, address, telephone number, ....).

    I would like to store everything in a list where each person would have an index "i" starting from 0 and increasing. The goal would be to retrieve a specific information about person by simply using the index "i" and an abbreviation to indicate the type of info to retrieve about that person (name, id, tel, addr, email, ...).

    How to define this and how to access specific elements for a given person?

    I have done this previously in Fortran using derived data types where I use the following to retrieve various elements for a given person:

    list(i)%name

    list(i)%id

    list(i)%tel

    list(i)%addr

    list(i)%email



    I couldn't define the info type (name, id, email, addr, tel, ...) in the list to use it for indexing.

    Continue reading...

Compartilhe esta Página