Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AI Progamming Exercises
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Mutote
AI Progamming Exercises
Commits
8aadbc0d
Commit
8aadbc0d
authored
1 year ago
by
Narender Kumar
Browse files
Options
Downloads
Patches
Plain Diff
22103962
parent
0d4af7c7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
2.7 Exercises.py
+16
-2
16 additions, 2 deletions
2.7 Exercises.py
4_9_Exercises/Question 1.py
+13
-0
13 additions, 0 deletions
4_9_Exercises/Question 1.py
with
29 additions
and
2 deletions
2.7 Exercises.py
+
16
−
2
View file @
8aadbc0d
...
...
@@ -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
))
...
...
This diff is collapsed.
Click to expand it.
4_9_Exercises/Question 1.py
0 → 100644
+
13
−
0
View file @
8aadbc0d
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"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment