0

I have been trying to fit the following list of words from a text file into one list comprehension:

file = open("Lincoln.txt", "r").read().split()

world_list = []                                            

for v in file:
    word_list.append(v.translate(str.maketrans("", "",string.punctuation)).lower())
    for i in word_list:
         if i != '':
            world_list.append(i)

This is succesful, but I'm not sure how to include the second part of the for loop in that same list comprehension:

word_list = [v.translate(str.maketrans("", "",string.punctuation)).lower() for i,v in enumerate(word_list)]

Without the second part, I still get empty strings from my word extraction:

click to see my output

Community
  • 1
  • 1
LD-DS-00
  • 315
  • 2
  • 8
  • 1
    Please do not share information as images unless absolutely necessary. See: https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors, https://idownvotedbecau.se/imageofcode, https://idownvotedbecau.se/imageofanexception/. – AMC Apr 01 '20 at 21:53

1 Answers1

1

edited

[i for i in (v.translate(str.maketrans("", "",string.punctuation)).lower() for v in word_list) if i != '']
andreis11
  • 1,133
  • 1
  • 6
  • 10