-1

I've got a question how to add the words to list without that "\n" symbol.

Having a file where are words e.g.:

GCC
GNU
gcc
project
and
compiler
Only
the
most
useful
options
are
listed
here

My code:

list1=[]

f = open('3700.txt', "r")
for line in range(17):
    list1.append(f.readline())

My result:

['GCC\n', 'GNU\n', 'gcc\n', 'project\n', 'and\n', 'compiler\n', 'Only\n', 'the\n', 'most\n', 'useful\n', 'options\n', 'are\n', 'listed\n', 'here\n']
squall
  • 139
  • 5

1 Answers1

0

str.strip is your friend:

list1=[]

f = open('3700.txt', "r")
for line in range(17):
    list1.append(f.readline().strip())
SuperStormer
  • 4,997
  • 5
  • 25
  • 35