Parse text from input

Working on a school project. Im looking for suggestions, how to parse a specific input. Especially what kind of technique would you use.

Input: “K 88.3”
Output in a table: “Potassium - 88.3”

Input: “Kalium 88.3”
Output in a table: “Potassium - 88.3”

Input: “xyz K 88.3 xyz 9”
Output in a table: “Potassium - 88.3”

So basically it should scan the input for [“K”, “Kalium”, “Potassium”] and fetch the next number after the text. I also want to scale this up for further input values.

I got inspired by the header/demo of this website and want to create something similar for a school project (other topic though)

Thank you!

Sounds like you’re on the right track to me. You could use the element abbreviation as a key (since it is one).

'K': {
    'names': ['Kalium', 'Potassium'],
    'idontknowwhatthisnumberis': 88.3
},
'Ca': {
 ...
}, 
...

Then you could iterate over the names if you can’t find it in the keys.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.