-
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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login
移动用户速领话费!