-
peng111说:
对tuple_01=(34,23,63,7,45)元组进行升序排序,不使用sort函数
§ Code
tuple_01 = (34,23,63,7,45)
list_01 = list(tuple_01)
list_01.sort()tuple_01 = tuple(list_01)
print(tuple_01)§ Output
stdout : ['(7, 23, 34, 45, 63)\n']
§ Markdown
3
使用一行代码实现统计tuple_02=(2,3,5,7,9,3,5,7)中每个元素出现的次数
§ Code
tuple_02 = (2, 3, 5, 7, 9, 3, 5, 7)
dict_01 = dict.fromkeys(tuple_02, 0)
for i in tuple_02:
dict_01[i] += 1
print(dict_01)§ Output
stdout : ['{2: 1, 3: 2, 5: 2, 7: 2, 9: 1}\n']
§ END OF DOC