84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
认证高级PHP讲师
Double ended queue
from collections import deque def string_reverse(string): d = deque() d.extendleft(string) return ''.join(d);
def rev(s): r = list() for c in s: r.insert(0, c) return ''.join(r)
str = "hello world" l = len(str) for i in range(l): print str[l - i - 1]
def reserveStr(s): length = len(s) result = '' for i in range(length): result += s[length - i - 1] return result
def reversed_index(n): for i in range(n-1, -1, -1): yield i test_string = "我爱北京天安门" new_string = "" for i in reversed_index(len(test_string)): new_string += test_string[i] print(new_string)
Double ended queue