Skip to content
Advertisement

Filter raw string with sheltered simbols, python

Is it any chance to get cities names from the following raw strings without heavy iterations?

JavaScript

need to get Älvsborg, Stockholm, etc, that is name of a cities, towns. Names will be different of cource

Function is already heavy with iterations, so that build or add-on functions/methods are preferable.

also it is possible to get them in the following format:

JavaScript

which doesn’t make job easier.

Thank you!

p.s. i can separate letters and sheltered symbols like this in FOR cycle:

JavaScript

And after that i still need to separate cities names somehow…

Advertisement

Answer

You can just use str.split:

JavaScript

The city name seems to be the last element:

JavaScript

It looks like you’re parsing HTML with BeautifulSoup. You may find it easier to select the proper elements directly instead of parsing what .get_text() produces.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement