huashan8 发表于 2017-4-28 06:42:45

Python Challenge (level 18)

URI: http://www.pythonchallenge.com/pc/return/balloons.html
Username: huge; password: file
说明:

解题方法:
import gzip, difflib
# Download the GNU zip file from:
# http://www.pythonchallenge.com/pc/return/deltas.gz
h = gzip.open("deltas.gz")
d = difflib.Differ()
part_1, part_2 = [], []
file_1, file_2, file_3 = [], [], []
for line in h:
part_1.append(line)
part_2.append(line)
h.close()
for line in list(d.compare(part_1, part_2)):
if line == "+":
file_1.append(line)
elif line == "-":
file_2.append(line)
else:
file_3.append(line)
for n, data in enumerate((file_1, file_2, file_3)):
temp = []
for line in data:
temp.extend()
h = open("%s.png" % (n + 1), "wb")
h.writelines(temp)
h.close()
# The third file is corrupt and won't be properly displayed by most image
# viewers. It should work in Gecko-based browsers such as Firefox, though
过关答案:
../hex/bin
页: [1]
查看完整版本: Python Challenge (level 18)