Python - Unsupported type(s) : range and range

前端 未结 4 1668
孤街浪徒
孤街浪徒 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条回答
  •  旧时难觅i
    2021-01-18 02:26

    As other answers have said, range() being an iterator is your problem, however, a simpler (in my view) solution is to generate the list from -30 to 30 then remove 0, rather than avoiding it:

    choice([i for i in range(-30, 30) if i != 0])
    

    Naturally, if your ranges were more disparate, this might become unwieldy.

提交回复
热议问题