读取文件python中的水平线

时间:2014-01-21 06:32:43

标签: python

所以我想提出一个suduko检查器代码。所需数据存储在外部文件中。我试图检查数字是否水平匹配。到目前为止,我有以下

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")

我想知道这是否可以检查水平数字

1 个答案:

答案 0 :(得分:1)

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")