# -*- coding:utf-8 -*-def scan(sentence):# 将已知的词汇放入列表中存储directions = ['north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', 'back']verbs = ['go', 'stop', 'kill', 'eat']stops = ['the', 'in', 'of', 'from', 'at', 'it']nouns = ['door', 'bear', 'princess', 'cabinet']tup = []# 将句子中的单词已空格分开并存在列表中words = sentence.split()# 遍历words中元素,以元组的形式给单词分类for word in words:# word = word.lower() # 全部转成小写if word in directions:sen = ('direction', word)elif word in verbs:sen = ('verb', word)elif word in stops:sen = ('stop', word)elif word in nouns:sen = ('noun', word)else: # 测试是否是数字try:word = int(word)sen = ('number', word)except ValueError:sen = ('error', word)tup.append(sen)return tup小结: 第一次接触到元组,元组其实就是一个不能修改的列表。使用测试用例也不是想象中那么省事呀(- _-!)。
详细解决方案
更复杂的用户输入之scan函数ex48(lexicon.py)
热度:80 发布时间:2023-12-29 19:14:31.0
相关解决方案
- Spring自动扫描 <context:componet-scan>和加了<context:include-filter>以后有什么区别
- 《Pro Oracle SQL》Chapter3-3.1 Full Scan Access Methods 之二
- 《Pro Oracle SQL》Chapter3-3.2 Index Scan Access Methods-3.2.1 Index Structure
- IP,VIP,SCAN IP之间的关系?解决办法
- IP,VIP,SCAN IP其间的关系
- Microsoft VBScript 运行时异常 (0x800A000D) 类型不匹配: 'scan'
- Spring自动扫描 <context:componet-scan>跟加了<context:include-filter>之后有什么区别
- 目录全掃描 (index full scan)
- oracle11g 如何没有Index Skip Scan
- 在SQL的查询分析器中怎么使用“SCAN…ENDSCAN”循环语句
- index seek和index scan 提高sql 效率,该怎么解决
- CUDA系列学习(5)GPU基础算法: Reduce, Scan, Histogram
- Intents.Scan.RESULT是干什么的
- 《Pro Oracle SQL》Chapter3-3.2.4 Index range scan
- 《Pro Oracle SQL》Chapter 3-3.2.5 Index Full Scan
- 《Pro Oracle SQL》Chapter3-3.2.6 Index Skip Scan
- 《Pro Oracle SQL》Chapter3-3.2.3 Index Unique Scan
- 《Pro Oracle SQL》Chapter3-3.2.2 Index Scan Types
- 为什么用scan.next()+ scan.nextLine()而不是scan.nextLine()
- JAVA:spring配置自动扫描装载单个或多个包<context:component-scan base-package=””/>
- 凸包问题的三种解法: 暴力,Graham Scan,分治
- index range scan,index fast full scan,index skip scan发生的条件
- PDA扫描 Geenk scan 的方法列表
- poj-3267-The Cow Lexicon-dp
- poj-3267-The Cow Lexicon
- 如何理解oracle 11g scan ip
- 更复杂的用户输入之scan函数ex48(lexicon.py)
- java.lang.RuntimeException: error trying to scan jar-file:
- poj3267The Cow Lexicon(简单dp 虽然我并不是很会)
- POJ3267 The Cow Lexicon(DP)