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.输入一组数据，以逗号分隔，求出这组数据的平均值、最大值、最小值，并按从小到大顺序排序。

'''

'''
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 = 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))
`