-1

My text file looks like this

{} /n {}/n

When I use readline, I get it as a list , like ['{}' , '{}]

how do I remove the string and read them as sets?

Scarlet
  • 9
  • 2

1 Answers1

0

This code work for you.

with open('yourfile.txt','r') as file:
    data = file.read().splitlines()
    data = [set(a[1:-1].split(',')) for a in data]
print(data)

You can use eval also here, But using eval might be dangerous.

with open('yourfile.txt','r') as file:
    data = file.read().splitlines()
    data = [eval(a) for a in data]
print(data)
codester_09
  • 5,622
  • 2
  • 5
  • 27