python大数据分析基础实践教程课后题

img

第一题解答参考代码:

x={}
while True:
    inp=input().lower()
    if inp=='':
        break
    if inp[-1] in x:
        x.setdefault(inp[-1]).append(inp)
    else:
        x[inp[-1]]=[inp]
print(x)


第二题:

sent='Nanjing University of Finance and Economics,School of Information Engineering'
new=[]
for x in sent.split():
    cnt=x.count('n')
    if cnt>=2:
        new.append(x)

new_sent=' '.join(sorted(new))
print(new_sent)

如对你有帮助,请采纳。点击我回答右上角【采纳】按钮。