Python Homework - creating a new list

前端 未结 6 870
闹比i
闹比i 2021-01-22 19:36

The assignment:

Write a function called splitList(myList, option) that takes, as input, a list and an option, which is either 0 or 1. If the

6条回答
  •  攒了一身酷
    2021-01-22 19:52

    edit

    Can you show the code where you are calling the splitList method?

    this was incorrect

    myList [i]
    

    is your problem, you can't have a space in there. python is VERY VERY VERY strict about syntax

    since people seemed to think they should downvote me, let me explain:

    by having that space, you effectively said myList (which is a list), and [i], which is a list literal with the value of 'i' at index 0....

    so you are passing two variables (one actual variable and one literal) into the append method, NOT separated by a comma, which will not work.

提交回复
热议问题