Sentence = input("type in sentence:").split()
以上将输入中的各个单词存储到列表中。但是现在如何将Sentence
中的每个单词替换为该单词的位置?
答案 0 :(得分:0)
使用map和index函数将字符串映射到其索引。
Sentence = str(input("Type in the sentence here:")).split(" ")
indexed_sentence = list(map(lambda x: Sentence.index(x), Sentence))
你也可以这样做:
indexed_sentence = [Sentence.index(x) for x in Sentence]
或
indexed_sentence = []
for x in Sentence:
indexed_sentence.append(Sentence.index(x))
或
indexed_sentence = []
for x in Sentence:
for count in range(len(Sentence)):
if x == Sentence[count]:
indexed_sentence.append(count + 1)
break
答案 1 :(得分:-1)
这样做:
$statement = $db_con->prepare("select * from student where student_id = :student_id");
$statement->execute(array(':student_id' => $_GET['student_id']));
$row = $statement->fetchAll(PDO::FETCH_ASSOC);