Python Forum

Full Version: What kind of list is this?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, one more question for the day.

This is a list - my_List = ["one", "two","three"]
This is a dictionary - my_Dict = dict({1: 'Geeks', 2: 'For', 3:'Geeks'})

What is this then? This has multiple delimiters enclosed in the list[] ... {}'s, :'s and []'s

applicants = [
    {
        "name": "Devon Smith",
        "programming_languages": ["c++", "ada"],
        "years_of_experience": 1,
        "has_degree": False,
        "email_address": "[email protected]",
    },
    {
        "name": "Susan Jones",
        "programming_languages": ["python", "javascript"],
        "years_of_experience": 2,
        "has_degree": False,
        "email_address": "[email protected]",
    },
    {
        "name": "Sam Hughes",
        "programming_languages": ["java"],
        "years_of_experience": 4,
        "has_degree": True,
        "email_address": "[email protected]",
    },
]

print (type(applicants))
print (applicants.name)
OUTPUT:
<class 'list'>
Traceback (most recent call last):
File "<string>", line 26, in <module>
AttributeError: 'list' object has no attribute 'name'

Thanks
It is an ordinary list which elements are 3 dictionaries. Try
print(applicants[0]['name'])
print([elem['name'] for elem in applicants])
Also try:
print(*[elem['name'] for elem in applicants])
... to display the unpacked list