Created
March 14, 2019 08:52
-
-
Save HoweChen/11923e0b1257149bccf54f1036955766 to your computer and use it in GitHub Desktop.
[一个for循环实现双向遍历]一个for循环实现双向遍历 #Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain # 这里要用itertool里的chain | |
# 因为在python2里 range() 返回list | |
# python3 里range 返回iterator,不能直接相加,要用chain方法 | |
for i in chain(range(n), range(n)[::-1]): # 这个写法可以实现一个for里双向遍历 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment