[英]How to read list with some conditions using python3?
How to read list with some conditions using python3? 如何在某些条件下使用python3读取列表?
By default i want to check the first list with date condition and second as alpha numberic condition and rest all list as numbers conditions. 默认情况下,我想检查第一个带有日期条件的列表,第二个作为字母数字条件,其余所有列表都作为数字条件。 Is it easy to check the condition in nested list or dictionary ??? 在嵌套列表或字典中检查条件是否容易? import 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
Yes, you can do this as bellow: 是的,您可以像下面这样进行操作:
for i,string in enumerate(list_1):
if i == 0 :
for j in string:
if re.findall(r"\d{1,2}/\d{1,2}/\d{4}", j):
print(j,"first")
elif i == 1:
for k in string:
if re.findall(r"[a-zA-Z0-9]", k):
print(k,"second")
else:
for l in string:
if re.findall(r"[0-9]", l):
print(l,"third")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.