1、使用列表生成式生成如下列表:[1,9,25,49,81]

s = [i**2 for i in range(1,10)if i%2==1]
print(s)

2、输入一个由英文单词组成的字符串(分隔符自定),将每个单词的长度计算出来并形成一个新列表,并统计所有单词的平均长度。

s = input("请输入一个由英文单词组成的字符串,空格作为分隔符").split()
num =len(s)
x =list()
for i in range(0,num):
       x.append(len(s[i]))
average =sum(x)/len(x)     
print(x)
print("平均单词长度%d",average)        

3.输入一组数据,以逗号分隔,求出这组数据的平均值、最大值、最小值,并按从小到大顺序排序。

'''
学习中遇到问题没人解答?小编创建了一个Python学习交流QQ群:857662006
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
s = input("请输入一组数据,逗号作为分隔符").split(',')
num = len(s)
x = list()
for i in range(0,num):
       x.append(int(s[i]))
average = sum(x)/len(x)
maxx = max(x)
minx = min(s)
list.sort(x)
print("数据的平均值为",average)
print("数据的最大值为",maxx)
print("数据的最小值为",minx)
print("数据从小到大排序为",x)   

4.统计《哈姆雷特》中出现频率最高的几个词

def getText():
       txt = open("D:\hamlet.txt","r").read()
       txt = txt.lower()
       for ch in '!"#%@^&*():?/{}[]\\_+,.~`<>|"’':
           txt = txt.replace(ch," ")
       return txt
hamletTxt = getText()
words = hamletTxt.split()
counts = {}
for word in words :
       counts[word] = counts.get(word,0) +1
items = list(counts.items())
items.sort(key=lambda x:x[1],reverse = True)
for i in range(10):
       word,count = items[i]
       print("{0:<10}{1:>5}".format(word,count))