当前位置:首页 » 编程语言 » 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-17 03:13:05 浏览:543
html文件上传表单 发布:2024-09-17 03:08:02 浏览:784
聊天软件编程 发布:2024-09-17 03:00:07 浏览:726
linuxoracle安装路径 发布:2024-09-17 01:57:29 浏览:688
两个安卓手机照片怎么同步 发布:2024-09-17 01:51:53 浏览:207
cf编译后没有黑框跳出来 发布:2024-09-17 01:46:54 浏览:249
安卓怎么禁用应用读取列表 发布:2024-09-17 01:46:45 浏览:524
win10设密码在哪里 发布:2024-09-17 01:33:32 浏览:662
情逢敌手迅雷下载ftp 发布:2024-09-17 01:32:35 浏览:337
安卓如何让软件按照步骤自动运行 发布:2024-09-17 01:28:27 浏览:197