Python - Unsupported type(s) : range and range

前端 未结 4 1624
孤街浪徒
孤街浪徒 2021-01-18 01:55

I\'m getting this strange error trying to run a script, the code appears to be correct but it seems python (3) didn\'t liked this part:

        def function(         


        
4条回答
  •  执笔经年
    2021-01-18 02:18

    This is because Python 3 range does not return a list, unlike Python 2. This code was written for Python 2.

    This code should be changed:

    range(-30,0) + range(1,30)
    

    It should be changed to:

    [*range(-30,0), *range(1,30)]
    

    Prior to Python 3.5 (2015, PEP 448 - Additional Unpacking Generalizations), you cannot use * inside lists, and must write it this way instead (or you may prefer this):

    list(range(-30,0)) + list(range(1,30))
    

提交回复
热议问题