元组中包含整数和含有整数及元组的元组,写函数viewALLInt访问其中所有整数
def viewALLInt(data):
for itme in data:
if type(itme) is int:
print(itme)
elif type(itme) is tuple:
viewALLInt(itme)
d = (5,((1,2,),3,(4,9)),6,(7,8))
viewALLInt(d)
请举几个具体的例子, 看看元组中除了整数还有什么其他的东西。
import re
def viewALLInt(data):
lis = re.findall('\d+', str(data))
for i in lis:
print(i)
if __name__ == '__main__':
d = (5, ((1, 2,), 3, (4, 9)), 6, (7, 8))
viewALLInt(d)