【发布时间】:2018-06-07 17:10:52
【问题描述】:
所以,我正在开发一个程序,将输入文本转换为 Discords region_indicator 表情符号,但问题是,如果输入诸如“cab”之类的单词,则输出将返回为“abc”。有没有办法改变程序,以便在输入单词时不按字母顺序排序。 (出于测试目的,我只编写了前 3 个字母。用 Python IDLE 3.5 编码)
import sys
sentence = input("Enter a sentence:")
sentenceLower = sentence.lower()
sentenceList = list(sentenceLower)
sentenceListLength = len(sentenceList)
while sentenceListLength > 0:
if "a" in sentence:
sys.stdout.write(":regional_indicator_a:")
sentenceListLength = sentenceListLength - 1
if "b" in sentence:
sys.stdout.write(":regional_indicator_b:")
sentenceListLength = sentenceListLength - 1
if "c" in sentence:
sys.stdout.write(":regional_indicator_c:")
sentenceListLength = sentenceListLength - 1
简而言之,程序接收一个句子,检查该句子中是否出现字母,然后打印出要复制并粘贴到 Discord 中的文本。
【问题讨论】:
-
我不确定我是否理解您要执行的操作,但我认为您可能希望遍历句子中的字符,而不是查找句子中的字符。
-
与我能在短时间内想到的最不有效的方法相比,这是一种效率较低的方法。