Python Forum
What type of *data* is the name of a list/tuple/dict, etc?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What type of *data* is the name of a list/tuple/dict, etc?
#5
For something like this I would use a dictionary or database depending on if the device list is fixed or fluid. This is an example of using a dictionary.
devices = {
    "0.1K1A":[1.942952*10**-3, 2.989769*10**-4, 3.504383*10**-7],
    "0.3K1A":[1.627660*10**-3, 2.933316*10**-4, 2.870016*10**-7],
    "1K2A"  :[1.373168*10**-3, 2.772261*10**-4, 1.997412*10**-7],
    "1K7A"  :[1.446059*10**-3, 2.683626*10**-4, 1.643561*10**-7],
    "2K3A"  :[1.498872*10**-3, 2.379047*10**-4, 1.066953*10**-7],
    "2.2K3A":[1.471388*10**-3, 2.376138*10**-4, 1.051058*10**-7],
    "3K3A"  :[1.405027*10**-3, 2.369386*10**-4, 1.012660*10**-7],
    "5K3A"  :[1.287450*10**-3, 2.357394*10**-4, 9.505200*10**-8],
    "10K3A" :[1.129241*10**-3, 2.341077*10**-4, 8.775468*10**-8],
    "10K4A" :[1.028444*10**-3, 2.392435*10**-4, 1.562216*10**-7],
    "30K5A" :[9.331754*10**-4, 2.213978*10**-4, 1.263817*10**-7],
    "30K6A" :[1.068981*10**-3, 2.120700*10**-4, 9.019537*10**-8],
    "50K6A" :[9.657154*10**-4, 2.106840*10**-4, 8.585481*10**-8],
    "100K6A":[8.271111*10**-4, 2.088020*10**-4, 8.059200*10**-8],
    "1M9A"  :[7.402387*10**-4, 1.760865*10**-4, 6.865999*10**-8]
}

def select_device():
    while True:
        for index, name in enumerate(devices):
            print(f'{index+1:2d}: {name}')
        name = input('Enter device name or number : ').upper()

        if not name in devices:
            try:
                name = list(devices.keys())[int(name)]
            except:
                pass

        dev = devices.get(name, None)
        if dev is not None:
            return name, dev

print(select_device())
alloydog likes this post
Reply


Messages In This Thread
RE: What type of *data* is the name of a list/tuple/dict, etc? - by deanhystad - Jan-13-2021, 08:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 615 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  using > < for tuple , list,... akbarza 3 614 Feb-05-2024, 01:18 PM
Last Post: deanhystad
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 587 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  Change font in a list or tuple apffal 4 2,823 Jun-16-2023, 02:55 AM
Last Post: schriftartenio
  search in dict inside tuple steg 1 774 Mar-29-2023, 01:15 PM
Last Post: rob101
  search a list or tuple for a specific type ot class Skaperen 8 2,113 Jul-22-2022, 10:29 PM
Last Post: Skaperen
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 9,552 Jul-15-2022, 04:04 AM
Last Post: ndc85430
  Membership test for an element in a list that is a dict value for a particular key? Mark17 2 1,313 Jul-01-2022, 10:52 PM
Last Post: Pedroski55
  Are list/dict comprehensions interpreted really sequentially? anata2047 3 1,543 May-31-2022, 08:43 PM
Last Post: Gribouillis
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 2,370 May-07-2022, 08:40 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020