#How to count a list?

1 messages · Page 1 of 1 (latest)

shrewd crescent
#

I have this list here and I want to count the number of patient there is.

patients = [Patient('Sara','Smith', 20, '07012345678','B1 234','Cold',''), Patient('Will','Smith', 24, '07012345678','B1 234','Diabetic',''),Patient('Sam','Jones', 21, '07012345678','B1 234','Cold',''), Patient('Mike','Jones', 37,'07555551234','L2 2AB','Diabetic',''), Patient('Daivd','Smith', 15, '07123456789','C1 ABC','Heart Disease','')]
safe topaz
#

len(patients)

#

Well, if you have a heterogeneous list, you can use a for loop, a counter and isinstance to check if the current object is a patient and update the counter

#

Since that's not the case right now, len will work fine.

shrewd crescent
#

I want something like```py
Registered Patients: 5

safe topaz
shrewd crescent
#

how do you do that

safe topaz
#

What?

shrewd crescent
#

how do you do the f string? I'm new to python, learning.

safe topaz
#

Read the article above 🙂

#

Basically, you can write code inside the curly braces

shrewd crescent
#
print('Registered Patients', {len(patients)}.format(patients))
#

like that

safe topaz
#

That's not an f string