Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
italojsoliveira committed Sep 21, 2024
1 parent 74c3e33 commit f3e359c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
23 changes: 21 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ else:

### Exercise 17: Counting the occurrence of each item in the list

Create a list with random numbers. Count the occurrence of each item in the list and store the result in a dictionary.
Create a list with pseudo-random numbers. Count the occurrence of each item in the list and store the result in a dictionary.

<details markdown=block>
<summary markdown=span>Click here to see a possible solution</summary>
Expand Down Expand Up @@ -402,7 +402,26 @@ print(element_count)

### Exercise 18

Checking if all elements in a list are unique
Create a list with pseudo-random integer numbers. Then, check all elements in this list are unique or not.

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

```python
import random as rd

my_list = []

for i in range(0,10):
my_list.append(rd.randint(0,100))

print(my_list)
if len(my_list) == len(set(my_list)):
print("All elements in this list are unique!")
else:
print("Not all elements in this list are unique!")
```
</details>

### Exercise 19

Expand Down
18 changes: 13 additions & 5 deletions set_1/ex18.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Checking if a file exists
# Create a list with pseudo-random numbers
# Check if all elements in this list are unique

import os
import random as rd

if os.path.isfile("file.txt"):
print("File exists!")
my_list = []

for i in range(0,10):
my_list.append(rd.randint(0,100))

print(my_list)
if len(my_list) == len(set(my_list)):
print("All elements in this list are unique!")
else:
print("File does not exists!")
print("Not all elements in this list are unique!")

8 changes: 1 addition & 7 deletions set_1/ex19.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
# Checking if a file exists
# Removing the occurrence of an item in a list

import os

if os.path.isfile("file.txt"):
print("File exists!")
else:
print("File does not exists!")
8 changes: 1 addition & 7 deletions set_1/ex20.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
# Checking if a file exists
# Flattening a nested list

import os

if os.path.isfile("file.txt"):
print("File exists!")
else:
print("File does not exists!")

0 comments on commit f3e359c

Please sign in to comment.