#269、写一个比较两个文本文件的程序,如果不同,给出第一个不同处的行号和列号;
file1="d:\\2019\\1.txt"
file2="d:\\2019\\2.txt"
with open(file1) as fp1:
content1=fp1.readlines()
with open(file2) as fp2:
content2=fp2.readlines()
if len(content1)>=len(content2):
lines_count=len(content1) #找到最多的行数
else:
lines_count=len(content2)
for i in range(lines_count):
if len(content1[i])>=len(content2[i]):
row_count=len(content1[i])
else:
row_count=len(content2[i])
for j in range(row_count):
if content1[i][j] != content2[i][j]:
print("第%s行,第%s列" %(i+1,j+1))
break
#270、给定一个Excel表格中的列名称,返回其相应的列序号。
def titleToNumber(s):
#26进制转10进制,A对应1,B对应2。。。。Z对应26
result = 0
for i in range(len(s)):
#参考2进制转10进制,从右边开始每个位置上的数字乘以26的i次方
num = (ord(s[-(i+1)]) - ord("A") + 1) * (26 ** i)
result += num
return result
print(titleToNumber("AA"))
print(titleToNumber("Y"))
print(titleToNumber("YZ"))
print(titleToNumber("FM"))
#271、给定一个文件 file.txt,转置它的内容。
with open("d:\\2019\\1.txt") as fp:
lines=fp.readlines()
write_lines=[]
write_line=""
for line in lines:
write_line=line[::-1]
write_lines.append(write_line)
print(write_lines)
with open("d:\\2019\\1.txt","w") as fp:
fp.writelines(write_lines)
#272、输入: [1,2,3] 输出:[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
l=[1,2,3]
result=[]
for i in l:
for j in l:
for k in l:
if i!=j and j!=k and i!=k:
result.append([i,j,k])
print(result)