Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do i append into dict?
#3
I´m assuming you want to create a list instead of a dictionary, cause you named your dictionary patientlist which is a contradiction.

But let´s assume you want to use a dictionary you need to do it this way.
patients = {}
for x in range(3):
   patient_name = input('Enter new name: ')
   patients[patient_name] = patient_name
for key, value in patients.items():
    print(key, value)
But using the same content for key and the value is nonsense imho.

So let´s assume you want to create a list of your patient names, do it this way.
patients = []
for x in range(3):
   patient_name = input('Enter new name: ')
   patients.append(patient_name)
for name in patients:
    print(name)
Reply


Messages In This Thread
How do i append into dict? - by Gateux - Aug-21-2019, 04:22 AM
RE: How do i append into dict? - by Malt - Aug-21-2019, 04:50 AM
RE: How do i append into dict? - by ThomasL - Aug-21-2019, 05:40 AM
RE: How do i append into dict? - by perfringo - Aug-21-2019, 06:59 AM
RE: How do i append into dict? - by Malt - Aug-22-2019, 04:24 AM
RE: How do i append into dict? - by perfringo - Aug-22-2019, 05:41 AM
RE: How do i append into dict? - by Malt - Aug-22-2019, 09:11 AM
RE: How do i append into dict? - by perfringo - Aug-22-2019, 10:46 AM
RE: How do i append into dict? - by ThomasL - Aug-26-2019, 08:18 AM
RE: How do i append into dict? - by perfringo - Aug-26-2019, 09:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Cant Append a word in a line to a list err "str obj has no attribute append Sutsro 2 2,655 Apr-22-2020, 01:01 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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