用数字重新创建句子

时间:2016-06-20 10:17:34

标签: python

所以我开发了一个代码,可以让你重新创建一个句子,但是有一个问题,它会删掉一个单词!我不知道为什么如果有人可以纠正它,那将是非常感谢!

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(self beginswith %@ OR self contains[CD] %@)",@"cloud",@",cloud"];
NSArray *arrResult = [arrData filteredArrayUsingPredicate:predicate];

1 个答案:

答案 0 :(得分:1)

这些lignes负责这种行为:

# length = len(numlist) -1 # <==== comment these lines
# del numlist[length]  # <==== comment these lines

将它们放入评论中,或将其删除:

Sentence = input("Please enter a sentence: ")
Sen = Sentence.split()
remove=(",")

numbers = input("Enter Numbers(Separating them with a comma for example 1,3,2): ")

newnumbers = ""
for char in numbers:

    if char not in remove:

        newnumbers = newnumbers + char + " "
numlist = newnumbers.split()

# length = len(numlist) -1 # <==== comment these lines
# del numlist[length]  # <==== comment these lines

savenum = " ".join(numlist) -1

file = open("Bruh.txt","w")
file.write(Sentence)
file.write("\n"+savenum)
file.close()

newli = []

for char in numlist:

    newnum = (int(char)-1) 
    newli = newli + [Sen[int(newnum)]]
words = " ".join(newli)

print("Original Sentence: ",Sentence)
print("Recreated Sentence: ", words)