Here is an example of a list of lists.
[["Amber", "7.3"], ["Molly", "14.5"], ["Lisa"]]As you can see, there are two lists that have a second element. These elements are strings but need to be converted into floats. The problem boils down to the last element in the list. The last element isn't a list, but just a string and I want my program to just ignore it.
I've tried a few different things but keep coming back to the basic
for i in lst: for x in i: float(x[1])But of course I get an error because ("lisa") doesn't have a x[1] for it to change. I still want Lisa to exist in my list, I just want the numbers specifically to become floats.
[["Amber", 7.3], ["Molly", 14.5], ["Lisa"]]I tend to overthink things so if something doesn't make sense or this isn't something I can do within python please let me know.
I apologize, I made a few mistakes when writing out my example which made things extremely confusing.This is for a school assignment so I was trying to get across what I needed while being as vague about my actual code as possible. The actual example above has nothing to do with said assignment. Someone asked below how the final item in the list is a different structure. I believe they may have been asking why, in my original code, there were both tuples and a string. This was because I'm stupid and forgot to double check my own work. In the code I meant to sent, all three elements in the list, are lists. The final one is different from the rest as my actual function has to do with reading a file composed of basic calculations but written in plain English. So each line of the file is essentially just doing basic math on a calculator, with the final list of one element representing an enter key.