Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
italojsoliveira committed Sep 15, 2024
1 parent e8ff825 commit d365d98
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
27 changes: 26 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,32 @@ else:

### Exercise 17

Counting the occurrence of an item in a list
Create a list with 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>

```python
import random

my_list = []

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

# Create an empty dictionary to store the counts
element_count = {}

# Iterate through the list and count occurrences
for element in my_list:
if element in element_count:
element_count[element] += 1
else:
element_count[element] = 1

print(element_count)
```
</details>

### Exercise 18

Expand Down
21 changes: 21 additions & 0 deletions set_1/ex17.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Create a list with random numbers.
# Count the occurrence of each item in the list and store the result in a dictionary

import random

my_list = []

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

# Create an empty dictionary to store the counts
element_count = {}

# Iterate through the list and count occurrences
for element in my_list:
if element in element_count:
element_count[element] += 1
else:
element_count[element] = 1

print(element_count)
8 changes: 8 additions & 0 deletions set_1/ex18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Checking if a file exists

import os

if os.path.isfile("file.txt"):
print("File exists!")
else:
print("File does not exists!")
8 changes: 8 additions & 0 deletions set_1/ex19.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Checking if a file exists

import os

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

import os

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

0 comments on commit d365d98

Please sign in to comment.