Python.Lists
来源:互联网 发布:网络调试助手下载 编辑:程序博客网 时间:2024/06/06 00:32
Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and print the resulting words in alphabetical order.
You can download the sample data at http://www.pythonlearn.com/code/romeo.txt
fname = raw_input("Enter file name: ")fh = open(fname)lst = list()for line in fh: for word in line.split(): if word not in lst: lst.append(word) lst.sort()print lst
输出:
Enter file name: romeo.txt['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'the', 'through', 'what', 'window', 'with', 'yonder']
0 0
- Python -- Lists
- Python.Lists
- Python中Lists浅析
- Python 列表(Lists)
- Python 列表(Lists)
- Python 列表(Lists)
- python 列表(Lists)
- Python HackerRank|Lists
- An Introduction to Python Lists
- python学习笔记15--Lists
- Think Python: Chapter 10 Lists
- 3.9.1 - Lists in Python
- An Introduction to Python Lists
- Python中的Numbers,Strings,Lists
- Python 入门教程 8 ---- Python Lists and Dictionaries
- Lists
- 【LeetCode with Python】 Merge Two Sorted Lists
- Beginning Python - Chapter2 : Lists and Tuples
- runloop 阻塞主线程
- Android开发,关于Canvas的使用,绘图的各种用法
- ThreadLocal
- [perl] perlbrew 与 local::lib 的并存时,模块在INC路径却不被搜索的问题及解决
- Html5之画布,尽情地画吧
- Python.Lists
- Ant和Maven的下载和安装
- WEBRTC TURNSERVER配置
- 【腾讯优测干货分享】Android5.0-6.0双卡适配指南
- jenkins安装配置
- HTTPS科普扫盲帖
- 哈夫曼编码(Huffman)Java实现代码简化版
- 解决Redis的Test replication partial resync: ok psync (diskless: yes, reconnect: 1)
- Ajax使用一+javascript解析Ajax返回的json字符串