【发布时间】:2022-01-01 23:12:12
【问题描述】:
我有这个字典:
{128: ['S', 'S', 'O', 'F'], 512: ['S', 'F']}
我想确保每个键都有一个值“F”和一个值“S”,如果不是这样,则返回一条消息
我试过了,但它似乎没有用: 它没有打印消息
for key in d:
if not re.search(r"[F]{1}","".join(d[key])) or not re.search(r"[S].{1}","".join(d[key])):
print(f"There is no start or end stop for the line {key}.")
谢谢
【问题讨论】:
-
它看起来不像一个正则表达式问题,您正在检查一个字符串是否等于某个值。此外,您的键是数字,没有字母。
标签: python string dictionary