Skip to content
Snippets Groups Projects
Commit 8aadbc0d authored by Narender Kumar's avatar Narender Kumar
Browse files

22103962

parent 0d4af7c7
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,21 @@ def rotateR(val):
return val[-1] + val[:-1] if len(val) > 0 else None
# question 2
def rotateL(val):
return val[:-1] + val[0] if len(val) > 0 else None
# question 3
"""
The provided functions rotateR and rotateL are designed to work with both strings and lists.
There's no issue with their functionality for either data type.
example rotateR using strings and lists -- rotateR("abc") == "cab" and rotateR([1,2,3,4]) == [4,1,2,3]
example rotateL using strings and lists -- rotateL("abc") == "bca" and rotateL([1,2,3,4 ]) == [2,3,4,1]
"""
# question 4
def rotateRx(val):
val[:] = [val[-1]] + val[:-1]
......@@ -16,9 +31,8 @@ def rotateRx_modified(val):
# So the only way to achieve this would be to return a value and assign it back.
pass
# question 6
# question 6
def rotateR2(val):
return rotateR(rotateR(val))
......
def reverse_list_or_string(input_list_or_string):
if len(input_list_or_string) == 0:
return input_list_or_string
else:
return reverse_list_or_string(input_list_or_string[1:]) + [input_list_or_string[0]]
# Example usage for reversing a list
my_list = [1, 2, 3, 4, 5]
print(reverse_list_or_string(my_list)) # Output: [5, 4, 3, 2, 1]
# Example usage for reversing a string
my_string = "Hello, World!"
print(''.join(reverse_list_or_string(list(my_string)))) # Output: "!dlroW ,olleH"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment