Python-programming-exercises问题10

Python-programming-exercises问题10

  • 问题:
    编写一个程序,该程序接受由空格分隔的单词序列作为输入,并在删除所有重复的单词并将其按字母数字顺序排序后打印这些单词。
    假设将以下输入提供给程序:
  • 输入:
    hello world and practice makes perfect and hello world again
  • 输出:
    again and hello makes perfect practice world
  • 我的:
s = list(input().split())
a = s[:]
l = len(s)
print(l)
for i in range(0,l-1):
    for j in range(i+1,l-1):
        if s[i] == s[j]:
            a.remove(s[j])
a.sort()
print(' '.join(a))
  • Solution:
s = input()
words = [word for word in s.split(" ")]
print (" ".join(sorted(list(set(words)))))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
“近年来程序设计领域最好的一本书。”——Larry O’Brien, Software Development Times, July 29, 2015 Using a simple computational task (term frequency) to illustrate different programming styles, Exercises in Programming Style helps readers understand the various ways of writing progr ams and designing systems. It is designed to be used in conjunction with code provided on an online repository. The book complements and explains the raw code in a way that is accessible to anyone who regularly practices the art of programming. The book can also be used in advanced programming courses in computer science and software engineering programs. The book contains 33 different styles for writing the term frequency task. The styles are grouped into nine categories: historical, basic, function composition, objects and object interactions, reflection and metaprogramming, adversity, data-centric, concurrency, and interactivity. The author verbalizes the constraints in each style and explains the example programs. Each chapter first presents the constraints of the style, next shows an example program, and then gives a detailed explanation of the code. Most chapters also have sections focusing on the use of the style in systems design as well as sections describing the historical context in which the programming style emerged. Cristina Videira Lopes,加州大学欧文分校信息学教授,致力于大规模数据和系统的软件工程研究。她是施乐帕洛阿尔托研究中心的创始成员,还研发并维护着一个搜索引擎,为基于OpenSimulator的虚拟世界提供帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值