python 字典的綜合練習題

2021-10-06 15:31:53 字數 675 閱讀 4046

# 數字重複統計:

1). 隨機生成1000個整數;

2). 數字的範圍[20, 100],

3). 公升序輸出所有不同的數字及其每個數字重複的次數;

import random

all_nums =

#定義空列表儲存數字

for item in

range

(1000):

20,100)

)# print(all_nums)

sorted_nums =

sorted

(all_nums)

#排序num_dict =

#定義空字典

for num in sorted_nums:

#迴圈遍歷,通過key值找value

if num in num_dict:

num_dict[num]+=1

else

: num_dict[num]=1

print

(num_dict)

可以看出:完成公升序輸出,並且value值對應的時出現的次數

python 字典練習題

標準的字典資料 dict 1 兩字典相加 one dict two list 兩個字典相加 合併為 第三個字典 one dict.update two list print one dict 修改字典 修改字典 one dict age 10 print one dict age 等同於 print...

Sed綜合練習題

1.將nginx配置檔案裡的第乙個server塊裡的listen的埠80 修改為8080 sed i r s listen.80 18080 p nginx.conf2.在nginx的配置檔案裡新增乙個server塊配置 server error page 404 404.html location...

python的練習題 Python練習題

1 使用while迴圈輸入1 2 3 4 5 6 8 9 10 i 0while i 10 i i 1 if i 7 continue print i 結果 e python python python test.py1 2 求1 100的所有數的和 i 0sum 0 while i 100 i 1...