final_list = [ ]
words = ['good', 'bad', 'excellent','delivery', 'quality','upset','better','poor','refund','fake','cheat','quick','long','scam','cheaper','aluminium']
def func(words, list1):
cnt = 0
final_list = [ ]
for i in list1:
no_of_words = len(i.split())
# print(no_of_words)
# print(i)
if no_of_words>2:
for word in i.split(): # Only printing the records where occurence of words >2
# print(word)
if word in words:
cnt+=1
if cnt>2:
final_list.append(i)
cnt = 0
return final_list
final_list = func(words, )
print( *final_list, sep = ' \n\n')
The above given code prints the row elements of the column 'list1' in which row elements contain words of the list 'words' where words > 2.
For eg. I am a good delivery person, but still customers cheat me sometimes.
Consider this to be one of the row elements. If this row is given it will get printed because (words>2) condition is satisfied i,e good,delivery, cheat are present in my list 'words'.
But I want to modify the function. Along with the above condition we also want to check if individual words>2 in the row element
for e.g.. I am a good delivery boy, I do good things to people, I don't cheat anyone, yet people are not good to me and cheat me often.
This above given example will not get printed. Because:
- Words>2 -> True //good, delivery , cheat are present ( words>2)
- Individual words>2 -> False // good- 3 times, delivery - 1 time , cheat - 2 times ( Doesn't satisfy the condition of individual items > 2, hence won't get printed)
Kindly help me modifying my function.