-5

What i am trying to do is read from a file, and insert the content from a file into a list in python 3. the file should look like this:

♥A
♣A
♥Q
♠Q

and the result i am expecting when i read from the file is that when i print the specific list is that it shows up like this

['♥A', '♣A', '♥Q', '♠Q']

How would i go about solving this?

And i have tried multiple solutions for this, like using for loops, but i dont understand how to do this

Roald Andre Kvarv
  • 179
  • 1
  • 3
  • 16

1 Answers1

0

You can use the open function.

f = open("file.txt", "r")

l = list()

for line in f:
    l.append(line)

f.close()

print(l)
Francois
  • 384
  • 2
  • 11