mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 14:56:27 -04:00
Faster, better, stronger
This commit is contained in:
parent
4a32dac35d
commit
7b79f5816a
1 changed files with 4 additions and 12 deletions
|
@ -1,25 +1,17 @@
|
|||
#!/usr/bin/python3
|
||||
# mari von steinkirch @2013
|
||||
# steinkirch at gmail
|
||||
|
||||
|
||||
def reverse_str(s):
|
||||
''' in place '''
|
||||
sr_ls = []
|
||||
for i in range(len(s)-1, -1, -1):
|
||||
sr_ls.append(s[i])
|
||||
return ''.join(sr_ls)
|
||||
|
||||
|
||||
reverse_string = lambda s: s[::-1]
|
||||
|
||||
|
||||
def main():
|
||||
s1 = 'abcdefg'
|
||||
s2 = 'buffy'
|
||||
s3 = ''
|
||||
print(reverse_str(s1))
|
||||
print(reverse_str(s2))
|
||||
print(reverse_str(s3))
|
||||
print(reverse_string(s1))
|
||||
print(reverse_string(s2))
|
||||
print(reverse_string(s3))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue