Skip to content
Advertisement

How to remove multiple substrings at the end of a list of strings in Python?

I have a list of strings:

JavaScript

If at the end of the string there is the word

limited, com or org I would like to remove it. How can I go about doing this?

I have tried;

JavaScript

I’ve also tried the replace function with no avail.

Thanks

Advertisement

Answer

You can use this example to remove selected last words from the list of string:

JavaScript

Prints:

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