When there is just one type of fruit in the string it is fine. However, when there are more than 2 of them I have a list of coexisting words and replacements (it is like a dictiorary):
I can remove one of fruits when they are next to each other in the string, however in my data there can be words between them and I do not know how to remove unnecessary word. The order of the words in the string might differ as well.
I want it to be like this:
Before
After
tasty apple
tasty apple
tasty orange
tasty orange
yellow banana
yellow banana
red tasty peach
red tasty peach
tasty banana apple
tasty apple
tasty apple yellow banana
tasty apple yellow
yellow orange banana
yellow banana
peach tasty apple
peach tasty
yellow banana tasty peach
yellow banana tasty
Maybe I can use some kind of regular expression to identify the words between words? But I need to save them and delete the unnecessary word only
Hello @ technocrat! There order here does not matter. What matters is what types of fruit are present in the string. For example, whan banana and apple are in the same string only apple should always be left no matter what.
However I can modify my dictionary and present 2 scenarious: when banana is first and when apple is first and in both cases the replacement will be an apple. But it does not solve the problem with other words between them
I came up with some code that follows...
I initially got 'yellow orange banana' for 7 as apparently orange is a fruit rather than a colour and so should be an option for being dropped. So I put it as the 4th priority to resolve that.
I have a remaining discrepancy on 8, as 'peach tasty apple' goes to tasty apple rathan than peach tasty, owing to apple being prioritised above peach ...