Can't sort my list because it is NoneType? Simple Python

前端 未结 2 1221
深忆病人
深忆病人 2020-12-03 12:35

I get this error when I try to figure out the low and high prices for my BeautifulSoup web scraper. I attached the code below. Shouldn\'t my list be a list of ints?

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 12:58

    intprices.sort() is sorting in place and returns None, while sorted( intprices ) creates a brand new sorted list from your list and returns it.

    In your case, since you're not wanting to keep intprices around in its original form simply doing intprices.sort() without reassigning will solve your issue.

提交回复
热议问题