diff --git a/docs/index.md b/docs/index.md index d18f1f2..11e4996 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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.
Click here to see a possible solution @@ -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. + +
+Click here to see a possible solution + +```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!") +``` +
### Exercise 19 diff --git a/set_1/ex18.py b/set_1/ex18.py index de407e8..021c0ff 100644 --- a/set_1/ex18.py +++ b/set_1/ex18.py @@ -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!") \ No newline at end of file + print("Not all elements in this list are unique!") + diff --git a/set_1/ex19.py b/set_1/ex19.py index de407e8..77f3b15 100644 --- a/set_1/ex19.py +++ b/set_1/ex19.py @@ -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!") \ No newline at end of file diff --git a/set_1/ex20.py b/set_1/ex20.py index de407e8..4078a8a 100644 --- a/set_1/ex20.py +++ b/set_1/ex20.py @@ -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!") \ No newline at end of file