[英]reading horizontal lines in file python
so i am trying to come up with a suduko checker code. 所以我想提出一个suduko检查程序代码。 Where the data required is stored in an external file. 所需数据存储在外部文件中的位置。 I am trying to check if the numbers match horizontally. 我正在尝试检查数字是否水平匹配。 so far i have the following 到目前为止,我有以下
filename=input("Enter filename:-")
with open(filename) as f: #opening files
content = f.readlines() #obtaining each lines
for line in lines: #check each line
numbers=line.split() #split each line # split(example 135246 into 1,3,5,2,4,6 )
newnumber=letter.sort() #arrange to 1,2,3,4,5,6
if newnumber=[1,2,3,4,5,6]:
print("valid")
else:
print("not valid")
i was wondering if this would work to check the horizontal numbers 我想知道这是否可以检查水平数字
filename=input("Enter filename:-")
with open(filename) as f: #opening files
for line in f:
numbers = [int(i) for i in line.strip()]
numbers.sort()
if numbers == list(range(1,7)):
print("valid")
else:
print("invalid")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.