zoukankan      html  css  js  c++  java
  • python字典练习

    #!/bin/python3.4
    # coding=utf-8
    
    class lexicon(object):
        def __init__(self):
            print "define a clase instance!"
    
        def scan(self, elements):
            # self.elements = raw_input()
            directionval = ('north', 'south', 'east', 'west')
            verbval = ('go', 'stop', 'kill', 'eat')
            nounval = ('door', 'bear', 'princess', 'cabinet')
            numval = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
            wordtypelist = {'direction':directionval, 'verb':verbval, 'noun':nounval, 'num':numval}
            element = elements.split()
            result = []
            res = ()
            for i in range(len(elements.split())):
                for key, element[i] in wordtypelist.items():
                    if element[i] in wordtypelist['direction']:
                        print("direction element: %s" %(key, element[i]))
                    elif element[i] in wordtypelist['verb']:
                        print("verb element: %s" %(key, element))
                    elif element[i] in wordtypelist['noun']:
                        print("type: %s element: %s" %(key, element[i]))
                        res = ('direction', element[i])
                        result.append(res)
                    elif element[i] in wordtypelist['num']:
                        print("type: %s element: %s" %(key, element[i]))
                    else:
                        print("element %s is not in dict!!") %(element[i])
                    res = (key, element[i])
                    result.append(res)
            return result
    
    if __name__ == '__main__':
        print("##### Start #####")
        sentence = raw_input(">> ")
        print("type: %s content: %s", type(sentence), sentence)
        stuff = lexicon()
        stuff.scan(sentence)
        print("##### End #####")
  • 相关阅读:
    普通的patch 和使用git 打patch
    c语言中的原子操作
    读写锁的简单说明
    source Insight 的常用设置
    git 一些常用的场景
    gdb 脚本 简单理解
    linux 中的errno 和 strerror(errno)
    C++中内存对齐原理详解
    如何安装windbg调试助手
    Windows中如何读写INI文件
  • 原文地址:https://www.cnblogs.com/noxy/p/6413775.html
Copyright © 2011-2022 走看看