0

If I receive a bunch of similar strings like:

banana
Banana-e
bAnana
banana

They all contain "banana" in them, and I want them all to be, just simply, "Banana"?

But, ofc, with others, like [orange, oranges, oRange] = Orange

What would be the correct python approach to this?

Edit: I already know what the outputs will be, just the inputs that can vary.

Edit2: I'll probably map all the outputs in a dict and see if the input string contains one of the keys. Probably not the most efficient way but it will do

  • Does this answer your question? [Longest common substring from more than two strings - Python](https://stackoverflow.com/questions/2892931/longest-common-substring-from-more-than-two-strings-python) – mkrieger1 Jun 23 '21 at 13:31
  • Obviously, convert all strings to lowercase first. – mkrieger1 Jun 23 '21 at 13:32
  • @mkrieger1 not exactly, I want to be able to choose the correct output – Sabrina Sampaio Jun 23 '21 at 13:32
  • I don't understand what you mean. e.g., using the function from [this answer](https://stackoverflow.com/a/32611507) does exactly what you want. – mkrieger1 Jun 23 '21 at 13:35
  • @mkrieger1 I guess i would still need to implement a dictionary from the desired output string if i used this answer you linked, right? – Sabrina Sampaio Jun 23 '21 at 13:40
  • 1
    I still don't understand what you mean. Please show an example of what exactly you want to achieve and how the answers I've linked are not working for you. – mkrieger1 Jun 23 '21 at 13:41
  • @mkrieger1 Sure. I'll provide an example, hope that helps. I have the following outputs I need (exactly like this, case sensitive): (im just gonna use database names) MariaDB PostgreSQL MySQL But the inputs can have all sorts of variations, like "postgres" "postgreSql" "postgres1" the only thing I am certain is that the inputs will all contain "postgres" in them. But the output must ALWAYS be exactly "PostgreSQL". And this goes on for many other strings – Sabrina Sampaio Jun 23 '21 at 13:46
  • Okay, I see. Then you can just use a dictionary, what has been the problem with that? – mkrieger1 Jun 23 '21 at 13:49
  • You could also use regular expression for advanced searchs and convert the string to lower-case if needed before. – Jérôme Richard Jun 26 '21 at 09:28

0 Answers0