Question: When I try to read from a file, I'm getting an annoying error, I think it's got something to do with the list format of the variables but I'm not sure.

If anyone can help with with this issue that would be great.
I think it's also got something to do with \n being printed at the end of the list.

This is my code:

Option 1
========

```
    def one():
        print ("")
        print ("You have chosen to read the file!")
        print ("")
        file = open("sentence.txt" , "r")
        words = file.readlines(1)
        nums = file.readlines(2)
        #Remove "\n"
        #This bit doesn't work, I'm not sure how to remove "\n" 

        #These were me trying to get rid of the "\n"
        #map(str.strip, words)
        #words = words.strip('\n')

        print(words)
        print (nums)
        print ("")
        #Reconstruct sentence here

```

Answer: 
The function `file.readlines()` does not take an argument for the number of lines, it reads all the lines of the file at once. (for the record, if you do pass an argument like `file.readlines(n)`, the argument `n` is a "hint" about the number of bytes to read...more info here at [Python's function readlines(n) behavior](https://stackoverflow.com/questions/14541010/pythons-function-readlinesn-behavior))

```
   def one():
        print ("")
        print ("You have chosen to read the file!")
        print ("")
        file = open("sentence.txt" , "r")
        lines = file.readlines() # read all the lines into a list
        words = lines[0]
        nums = lines[1]
        #Remove "\n"
        #This bit doesn't work, I'm not sure how to remove "\n" 

        #These were me trying to get rid of the "\n"
        #map(str.strip, words)
        words = words.strip("\n][").replace("'", "").split(",")

        nums = nums.strip("\n][").replace("'", "").split(",")
        nums = list(map(int, numbers))  ## assuming you want to convert the string to integers, use this

        print(words)
        print (nums)
        print ("")
        #Reconstruct sentence here
        remade_sentence = ' '.join([words[i-1] for i in nums])  ## changed empty string to space to add spaces
        print (remade_sentence)

        file.close() ## also, make sure to close your file!

```

EDIT: I have updated the code to deal with `nums` being a list of strings.  

EDIT 2: updating code to reflect @notevenwrong's method of removing brackets and quotes

EDIT 3: Resimplifying...when I open my input file in a text editor, I literally see:

```
['the', 'dog', 'cat']
[1, 1, 1, 2, 1, 3]

```

If that is not the right input, then this code may not work.
You are getting exception at [words[i-1], Because i is str and you can perform -: 'str' and 'int'. 

```
>>> i = '1'
>>> i -1

Traceback (most recent call last):
  File "<pyshell#101>", line 1, in <module>
    i -1
TypeError: unsupported operand type(s) for -: 'str' and 'int'

```

A quick fix should be- 

```
remade_sentence = ''.join([words[int(i)-1] for i in nums])

```