7-46 jmu-python-求单词长度 (10 分)

输入n个单词,计算每个单词长度。对单词长度排序,分行输出单词长度及其单词。

输入格式:

  • 行1:单词个数n
  • 分行输入n个单词

输出格式:

分行输出单词长度及其单词。(单词长度,单词)用元组表示

输入样例:


5
python
list
set
996
tuple

输出样例:

(3, '996')
(3, 'set')
(4, 'list')
(5, 'tuple')
(6, 'python')
n = int(input())
ls = []
for i in range(n):
    s = input()
    ls.append(s)
ls.sort(key=lambda x:len(x),reverse=False)
for e in ls:
    print("({}, '{}')".format(len(e),e))

  

猜你喜欢

转载自www.cnblogs.com/aimilu/p/11819165.html