Accidentally changed definition of the function list now I can’t run codes

Hello, I was learning about defining functions in fundamentals and I wrote this code:

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

def list(a_row):
    For a_row in apps_data:
       that_row = float(a_row)
return a_list

Now the definition of the list function has changed and I can’t run codes any more and even when I click on restore initial code, when I run any code with list function I get this error because of list definition change:

TypeError                                 Traceback (most recent call last)
<ipython-input-1-0ba9fba6fdf2> in <module>
      2 from csv import reader
      3 read_file = reader(opened_file)
----> 4 apps_data = list(read_file)

<ipython-input-1-30c3ee41a750> in list(a_row)
      6     a_list=[]
      7     for a_row in apps_data:
----> 8         that_row = float(a_row)
      9         a_list.append(that_row)
     10     return a_list

TypeError: float() argument must be a string or a number, not 'list'

Is there anything I can do to change it back?

Hi @a.harati1993,

  1. When you create a function, avoid using reserved keywords as a function name, such as a name of another standard function, method, etc. list is a reserved keyword.
  2. As the error says, you cannot apply float() to a list of items, only to a string or a number. And a_row is a list.
  3. Inside your function, use for inside of For. Also, please mind indentation inside a for-loop and for the return statement.

After fixing these issues, it should work.

Hi @Elena_Kosourova , I just slept through the night and the issue was fixed but thanks anyway. and alsothank you for the reminders. wish you the best.

1 Like