Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
italojsoliveira committed Oct 3, 2024
1 parent 5bda5d2 commit 77ca93c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
18 changes: 15 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _This is a work in progress_. The last commit shows the latest updates.
- [Exercise 20: Flattening a nested list](#exercise-20-flattening-a-nested-list)
- [Exercise 21: Merging two dictionaries](#exercise-21-merging-two-dictionaries)
- [Exercise 22: Removing all whitespace from a string](#exercise-22-removing-all-whitespace-from-a-string)
- [Exercise 23](#exercise-23)
- [Exercise 23: Checking if a string is a palindrome](#exercise-23-checking-if-a-string-is-a-palindrome)
- [Exercise 24](#exercise-24)
- [Exercise 25](#exercise-25)
- [Exercise 26](#exercise-26)
Expand Down Expand Up @@ -482,9 +482,21 @@ print(new_string)
```
</details>

### Exercise 23
### Exercise 23: Checking if a string is a palindrome

Checking if a string is a palindrome
Palindrome is a word, phrase, or sequence that reads the same backwards as forwards, e.g. madam or nurses run. Write a program that checks if an arbitrary string is a palindrome.

<details markdown=block>
<summary markdown=span>Click here to see a possible solution</summary>

```python
my_string =input('Enter a string to check if it is a palindrome: ')
if my_string[::-1] == my_string:
print(my_string, "is a palindrome.")
else:
print(my_string, "is not a palindroe.")
```
</details>

### Exercise 24

Expand Down
12 changes: 8 additions & 4 deletions problem_set/ex23.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Flattening a nested list
# Palindrome is a word, phrase, or sequence that reads the same backwards as forwards, e.g. madam or nurses run.
# Checking if a string is a palindrome

my_list = [[1,2], [3,4], [5,6]]
flattened_list = [x for sublist in my_list for x in sublist]
print(flattened_list)
my_string =input('Enter a string to check if it is a palindrome: ')

if my_string[::-1] == my_string:
print(my_string, "is a palindrome.")
else:
print(my_string, "is not a palindroe.")

0 comments on commit 77ca93c

Please sign in to comment.