如何使用python3在某些条件下读取列表
默认情况下,我想检查第一个列表的日期条件,第二个作为alpha numberic条件,其余所有列表作为numbers条件。在嵌套列表或字典中检查条件容易吗??? 进口re
list_1=[["01/01/2019","02/02/2019"],["abc012","def345"],["1","2"],["2.50","3.15"],["4.50","5.55"]]
for i,string in enumerate(list_1):
for j in string:
if re.findall(r"\d{1,2}/\d{1,2}/\d{4}", j):
print(j,"first")
for k in string:
if re.findall(r"[a-zA-Z0-9]", k):
print(k,"second")
for l in string:
if re.findall(r"[0-9]", l):
print(l,"third")
Expected Output:
01/01/2019,first
02/02/2019,first
abc012 second
def345 second
1 third
2 third
2.50 third
3.15 third
4.50 third
5.55 third
是的,你可以这样做:
相关问题 更多 >
编程相关推荐