Created
January 8, 2023 20:42
-
-
Save SpotlightForBugs/90b6d6527fcabf833b1d9c564ab3b41e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
1. Create a sentence "i do not not like not to swim" | |
2 . create a list of negations | |
2. count all negations in the sentence | |
3. if the amount of negations is even, then remove all negations from the sentence, else remove all but the first | |
""" | |
negations = ["not", "no","n't"] | |
sentence = "i do not not like not to swim" | |
# Counting the number of negations | |
count = 0 | |
for word in sentence.split(): | |
if word in negations: | |
count += 1 | |
# Removing the negations accordingly | |
if count % 2 == 0: | |
new_sentence = "" | |
for word in sentence.split(): | |
if word not in negations: | |
new_sentence += word + " " | |
else: | |
new_sentence = "" | |
first_negation = True | |
for word in sentence.split(): | |
if word not in negations or first_negation: | |
new_sentence += word + " " | |
if word in negations: | |
first_negation = False | |
print(new_sentence) # i do like to swim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment