Faq python lists medical insurance

Why is it not outputting although I have followed the instructions correctly?
Line 13 is giving an error:

Traceback (most recent call last):
File “script.py”, line 13, in
TypeError: ‘<’ not supported between instances of ‘str’ and ‘float’

Edit: https://gist.github.com/e7d16917140e4c54b781c01ee2fd3815

Do you have a link to the lesson and some code to post?

1 Like

What happens if you comment out the offending lines and just print this?:

middle_five_records= medical_records[3:8]

I would try to break up the code, comment out lines and use print() to see what works and what doesn’t first…

You might want to double check how you’re appending this cost to the list here:

# Add your code here

medical_records = list(zip(insurance_costs, names))

Is that supposed to be a float or a string? What is that costs list?


The mistake was in the append function, I put double quotes while I shouldn’t have.
Thank you so much, @lisalisaj!!! For the quick response as well. :slight_smile:

1 Like

Sure, no problem! :slight_smile:
It’s also b/c the built in function .sort() won’t sort a list of strings and floats (like you had with the insurance costs list). If that list was converted to a tuple you could use the key argument to list.sort BUT, that’s not what is asked in the lesson. :slight_smile:

See here.

1 Like

I saw the link you sent, but I need you to give a simple example on how to use a key. Will be grateful!

you’d have to first create a dictionary which gives you the ordering of the types (if your list is str and float). then you have to define a function that converts the items to a tuple and will return the priority of the item(s)…etc.

But, to me, this is waaaay more work than you need to do. Just have to be careful when adding float values to a list of float values and not erroneously add them as a string, ie: with quotes, “8320.0”.

1 Like

Ok! Noted. Thank you so much. : )