我写了一个函数来检查数据是否正确。要求如下:
byr-(出生年份) - 四位数字;至少 1920 年,最多 2002 年。
iyr (Issue Year) - 四位数字;至少 2010 年,最多 2020 年。
eyr (Expiration Year) - 四位数字;至少 2020 年,最多 2030 年。
def check_byr_iyr_eyr(line):
statement = True
if line[:3] == "byr":
if (len(line[line.index(':')+1:]) != 4 or
1920 > int(line[line.index(':')+1:]) > 2002 ):
statement = False
elif line[:3] == "iyr":
if (len(line[line.index(':')+1:]) != 4 or
2010 > int(line[line.index(':')+1:]) > 2020 ):
statement = False
elif line[:3] == "eyr":
if (len(line[line.index(':')+1:]) != 4 or
2020 > int(line[line.index(':')+1:]) > …Run Code Online (Sandbox Code Playgroud) 从 .txt 文件读取行时遇到问题。我的文件包含带有以下单词的句子
\n\n\n没有\xe2\x80\x99t ,可以\xe2\x80\x99t ,没有\xe2\x80\x99t
\n
等等,问题是当我使用read()方法时
\n\n\xe2\x80\x99
\n
我有类似的东西:
\n\n\n\xc3\xa2\xe2\x82\xac\xe2\x84\xa2
\n
所以我读到的词hadn\xc3\xa2\xe2\x82\xac\xe2\x84\xa2t是hadn\xe2\x80\x99t
我的输入:
\nLove at First Sight\n\nOne <adjective> afternoon, I was walking by the <place> when\naccidentally I bumped into a <adjective> boy.\nAt first I blushed and apologized for bumping into him, but when he flashed his\n<adjective> smile I just couldn\xe2\x80\x99t help falling in love. His\n<adjective> voice telling me that it was ok …Run Code Online (Sandbox Code Playgroud)