0
Delete a word next to another one(python)
i need to do the capslock part of this code list1["red","one"] import random #input input1=input("min 3 words").split() print(" ") if ("dei")in input1: input1.remove(#REMOVE THE WORD NEXT TO DEI) text=" ".join(input1) print(text, random.choice(list1))
2 Antworten
+ 1
if i get your request right you want this:
if "dei"in input1:
input1.remove(input1[input1.index("dei")+1])
text=" ".join(input1)
print(text, random.choice(list1))
with the list.index() function you call the index of 'dei' and then you can go one further by adding 1 to the index. Plugging that index to the list to get the word which than can be removed.
0
def removeNext(str1, str2):
rtn = ""
skips = 0
toSkip = False
for word in str1.split():
if(toSkip):
toSkip = False
continue
if(word == str2):
if(skips == 0):
toSkip = True
skips = 1
rtn = rtn + word + " "
else:
rtn = rtn + word + " "
return rtn[:-1]
a = "de dei di"
if("dei" in a.split()):
input1 = removeNext(a, "dei")