mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-23 00:41:19 -04:00
Change the dir structure slightly
This commit is contained in:
parent
6b6fe21db3
commit
2f4a9638c0
184 changed files with 0 additions and 21 deletions
45
source_code/builtin_structures/reverse_words.py
Executable file
45
source_code/builtin_structures/reverse_words.py
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
__author__ = "bt3"
|
||||
|
||||
|
||||
|
||||
def reversing_words(word):
|
||||
"""
|
||||
>>> reversing_words('buffy is awesome')
|
||||
'awesome is buffy'
|
||||
"""
|
||||
new_word = []
|
||||
|
||||
words = word.split(' ')
|
||||
for word in words[::-1]:
|
||||
new_word.append(word)
|
||||
|
||||
return " ".join(new_word)
|
||||
|
||||
|
||||
def reversing_words2(s):
|
||||
"""
|
||||
>>> reversing_words2('buffy is awesome')
|
||||
'awesome is buffy'
|
||||
"""
|
||||
words = s.split()
|
||||
return ' '.join(reversed(words))
|
||||
|
||||
|
||||
def reversing_words3(s):
|
||||
"""
|
||||
>>> reversing_words('buffy is awesome')
|
||||
'awesome is buffy'
|
||||
"""
|
||||
words = s.split(' ')
|
||||
words.reverse()
|
||||
return ' '.join(words)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue