【问题标题】:Converting a raw list of words in Wordpad into a standard formatted python list将写字板中的原始单词列表转换为标准格式的 python 列表
【发布时间】:2016-06-17 04:37:10
【问题描述】:

我在写字板文档中有三个原始单词列表(只有单词后跟 enter)。我需要在我的 python 程序中使用这些列表。有没有一种方便的方法来访问这些单词或自动为 python 2.7 列表应用正确的格式?我不想在所有这些上手动输入 ['', '', ''] -es,因为每个列表中大约有 1,000 个单词。

我是这方面的初学者,真的试图用谷歌搜索,但无法正确表达问题,因为结果只针对不同的问题。

【问题讨论】:

    标签: python-2.7


    【解决方案1】:
    file_origin = open ("file_origin.txt", "r", encoding='utf-8')
    
    result = []
    
    for word in file_origin:
        result.append(word[:len(word)-1])
    
    file_origin.close()
    print(result)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多