I am creating a list from a.txt where each element is a line in the txt file with the code:
var_names = []
with open('filevarname.txt', 'r') as f1:
var_names = f1.readlines()
and this does produce the list, however, each element ends with "\n" so the var_names list looks like
var_names = [ 'var_name1\n', 'var_name2\n', 'var_name3\n', 'var_name4\n']
I have tried to use
var_names = map(lambda s: s.strip(), var_names)
and
var_names = map(lambda line: line.rstrip('\n'), var_names)
but when I run those line of codes the lists disappear, it's like it is getting deleted.
I know I'm missing something obvious, but it's not obvious to me so any help would be much appreciated.
I'm using spyder on a mac if that makes a difference.