【发布时间】:2016-02-16 02:37:23
【问题描述】:
这里是 Python 初学者。 我有一个函数应该打开两个文件,在空格处拆分它们,并将它们存储在列表中,以便在另一个函数中访问。 我的第一个函数类似于:
listinput1 = input("Enter the name of the first file that you want to open: ")
listinput2 = input("Enter the name of the first file that you want to open: ")
list1 = open(listinput1)
list1 = list(list1)
list2 = open(listinput2)
list2 = list(list2)
metrics = plag(list1, list2)
print(metrics)
但是当我执行第二个函数时,我看到列表没有像我预期的那样在空格处拆分。我已经尝试了 split 函数,并且我还尝试使用 for 循环来迭代列表的每个增量。
【问题讨论】:
-
list1 = list1.read().split() -
@Boosted,按空格分割还是全部空格?
-
@PadraicCunningham 仅限空格。
-
@AvinashRaj 谢谢你,这很有帮助!