當前位置:首頁 » 編程語言 » python元組個數

python元組個數

發布時間: 2024-07-27 07:49:23

python如何統計元組中重復元素個數

#獲取重復元數的個數,使用set可以將list中重復元數去掉
temp_list = [1, 3, 2, 3, 2, 4]
repeat_count = len(temp_list) - len(set(temp_list))

⑵ python 生成包含100個兩位數隨機整數的元組

#!usr/bin/python
#-*-coding:utf-8-*-
#python2.7

#分解需求
#1.生成2位數隨機數那麼就是random.randint(10,99)
#2.生成100個那麼就是foriinrange(100)
importrandom
random_tuple=tuple(random.randint(10,99)foriinrange(100))
printrandom_tuple
#字典dict_num={'數字':'出現的次數'}
dict_num={}
foriinrandom_tuple:
ifdict_num.get(i):
dict_num[i]+=1
else:
dict_num[i]=1
printdict_num

⑶ Python中如何使生成器函數來用元組返回一個字元串大寫字母個數和小寫字母個數

#如何使生成器函數來用元組返回一個字元串大寫字母個數和小寫字母個數

def getUorL(s):

# [A-Z]是匹配內容,str是待匹配的對象

rtn = f"大寫字母個數: {len(re.findall('[A-Z]',s))}"

yield rtn

# [a-z]是匹配內容,str_是待匹配的對象

rtn = f"小寫字母個數: {len(re.findall('[a-z]',s))}"

yield rtn


str = "10ABC23sD~45ffe67e;oo++"


#第一次返回大寫

g = getUorL(str)

print(next(g))


#第二次返回小寫

print(next(g))


熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:637
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:366
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:82
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:308
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:789
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:339
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:210
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:810
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:364
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:590