Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What kind of list is this?
#1
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
Reply
#2
It is an ordinary list which elements are 3 dictionaries. Try
print(applicants[0]['name'])
print([elem['name'] for elem in applicants])
BashBedlam and jesse68 like this post
Reply
#3
Also try:
print(*[elem['name'] for elem in applicants])
... to display the unpacked list
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  splitting lines, need to add element of same kind tester_V 6 3,153 Feb-20-2021, 11:51 PM
Last Post: tester_V
  What kind of object is this? Moris526 5 2,529 Dec-27-2020, 06:41 AM
Last Post: Gribouillis
  How to do this kind of IF STATEMENT? glennford49 4 2,655 Jun-17-2020, 09:45 AM
Last Post: glennford49
  How to write a code to get this kind of output in IDLE kavindu 5 3,584 Oct-28-2018, 07:46 PM
Last Post: wavic
  Newbie question for a kind of rolling average of list of lits zydjohn 3 3,346 Dec-16-2017, 11:41 PM
Last Post: ezdev
  Compiler fault or some kind of weird referencing bug? Joseph_f2 11 9,215 May-09-2017, 08:50 PM
Last Post: volcano63

Forum Jump:

User Panel Messages

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