문제

I know python 2to3 changes all xrange to range and I don't see any problem with this. My question is about how it changes range(...) into list(range(...)): is it dumb and just blindly search and replaces them all, or is it smart enough to tell when the list isn't needed and leaving it as range would be better?

도움이 되었습니까?

해결책

I don't know how intelligent it really is, but it certainly doesn't add list() to every range().

For example, the following:

print(range(10))

is changed to:

print(list(range(10)))

However, the following:

for el in range(10):
  print(el)

is left untouched.

This clearly indicates that it's more sophisticated than a blind search-and-replace.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top