當前位置:首頁 » 編程語言 » 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))


熱點內容
頻率計源碼 發布:2024-09-08 07:40:26 瀏覽:778
奧迪a6哪個配置帶後排加熱 發布:2024-09-08 07:06:32 瀏覽:100
linux修改apache埠 發布:2024-09-08 07:05:49 瀏覽:208
有多少個不同的密碼子 發布:2024-09-08 07:00:46 瀏覽:566
linux搭建mysql伺服器配置 發布:2024-09-08 06:50:02 瀏覽:995
加上www不能訪問 發布:2024-09-08 06:39:52 瀏覽:811
銀行支付密碼器怎麼用 發布:2024-09-08 06:39:52 瀏覽:513
蘋果手機清理瀏覽器緩存怎麼清理緩存 發布:2024-09-08 06:31:32 瀏覽:554
雲伺服器的優點與缺點 發布:2024-09-08 06:30:34 瀏覽:734
上傳下載賺錢 發布:2024-09-08 06:14:51 瀏覽:258