1

Here is the entire question I am trying to solve:

Implement a function getCustomerList that takes as argument filename to read the file and return it as a nested list, where each element is a list of [, <Clerk’s Desk>, ]. The filename argument doesn’t contain the extension (i.e. “input”), your program must automatically add the “.txt” extension. If the file doesn’t exist, the getCustomerList function will print the message: “Error! not found.”, and should return None.

My Problem: I am having trouble in getting the last item (minutes) to return WITHOUT quotes.

Here are my expected and actual results:

Name, Desk, Minutes

Expected vs Actual results

Here is my code:

My code

def getCustomerList(filename):
    current_file = filename + ".txt"
    data = []

    # write code to check if file exist and return List/None
    try:
        open_file = open(current_file, "r")
   
        for aline in open_file:
            values = aline.split(",") # Break each line into a list
            lines = [(n.rstrip('\n')) for n in values]
            data.append(lines) # Add the row to the list
        return data[1:]
        print(data)
    
    except IOError:
        print("Error! " + current_file + " not found.")
grvcmd
  • 21
  • 3
  • @user202729 Thank you for the comment. I have updated my post. – grvcmd Feb 12 '21 at 02:14
  • Post the text for the expected output too (people might want to copy and paste it to run your code) – user202729 Feb 12 '21 at 02:16
  • Although it looks like that you're looking for [How to convert strings into integers in Python? - Stack Overflow](https://stackoverflow.com/questions/642154/how-to-convert-strings-into-integers-in-python) . – user202729 Feb 12 '21 at 02:16
  • @SuperStormer Thank you for the link, it helped me figure out my problem! – grvcmd Feb 12 '21 at 03:25

2 Answers2

1

You are trying to transform into an integer? You can transform the last string of the list.

l = ['Annabel', 'A', '17']
l[-1] = int(l[-1])
print(l)
Leo
  • 55
  • 1
  • 6
0

I got it working:

Actual: [['Annabel', 'A', 17], ['Edgar', 'B', 19]]

Expected: [['Annabel', 'A', 17], ['Edgar', 'B', 19]]

Here is what I **added**:

    data.append(lines) # Add the row to the list

**for line in data [1:]:
    line[2] = int(line[2])**

return data[1:]
grvcmd
  • 21
  • 3