面试题答案
一键面试def read_file(file_path):
with open(file_path, 'r') as f:
lines = f.readlines()
desc = lines[0].strip()
points = []
for line in lines[1:]:
nums = line.strip().split(',')
for i in range(0, len(nums), 2):
x = int(nums[i])
y = int(nums[i + 1])
points.append((x, y))
return desc, points
你可以这样调用函数:
file_path = 'your_file.txt'
desc, points = read_file(file_path)
print("文本描述:", desc)
print("坐标点:", points)