我想创建一个类来导入文本文件中的每个单独的行,如果可能的话将元素转换为 int,然后将这些对象附加到列表中。
另外,如果文本文件中的行超过 6 个单词,我想让前 2 个单词一起保存在列表中。
例如,我导入一个文本文件,如:
Hi my age is 15 16
If you want 13 to add
Please use 0 to add to it
用 3 个单独的对象制作一个列表,
[
['Hi', 'my', 'age' 'is', 15, 16],
['If', 'you', 'want', 13, 'to', 'add'],
['Please use', 0, 'to', 'add', 'to', 'it',]
]
对python完全陌生,我希望能得到一些帮助,在此先感谢!