This shows you the differences between two versions of the page.
ewis:laboratoare:02 [2021/03/17 17:04] alexandru.predescu [Modules] |
ewis:laboratoare:02 [2023/03/15 17:40] (current) alexandru.predescu [Data Structures] |
||
---|---|---|---|
Line 79: | Line 79: | ||
new_elem = elem / s | new_elem = elem / s | ||
new_list.append(new_elem) | new_list.append(new_elem) | ||
+ | | ||
+ | # TODO: same task with list comprehension | ||
+ | | ||
return new_list | return new_list | ||
| | ||
Line 95: | Line 98: | ||
<note> | <note> | ||
- | //module1.py// | + | **//module1.py//** |
<code python> | <code python> | ||
Line 102: | Line 105: | ||
</code> | </code> | ||
- | //main.py// | + | **//main.py//** |
<code python> | <code python> | ||
Line 152: | Line 155: | ||
print(my_list) | print(my_list) | ||
- | # check if an element is found in the list (python specific, normally used with sets or dictionaries) | + | # check if an element is found in the list |
+ | # (python specific, normally used with sets or dictionaries) | ||
print(1 in my_list) | print(1 in my_list) | ||
print(10 in my_list) | print(10 in my_list) | ||
Line 164: | Line 168: | ||
<note> | <note> | ||
- | Create, access, check membership | + | **Create, access, check membership** |
<code python> | <code python> | ||
Line 179: | Line 183: | ||
</code> | </code> | ||
- | Modify | + | **Modify** |
<code python> | <code python> | ||
Line 203: | Line 207: | ||
</code> | </code> | ||
- | Operations (set theory) | + | **Operations (set theory)** |
<code python> | <code python> | ||
Line 239: | Line 243: | ||
**T4 (4p)** The set is a collection of unordered (and unique) elements. Use this to your advantage to remove duplicates from a list | **T4 (4p)** The set is a collection of unordered (and unique) elements. Use this to your advantage to remove duplicates from a list | ||
- | Tip: | + | Hint: |
*you can create a set from a list: ''s = set([1,2,3])'' | *you can create a set from a list: ''s = set([1,2,3])'' | ||
*you can create a list from a set: ''v = list({1, 2, 3})'' | *you can create a list from a set: ''v = list({1, 2, 3})'' | ||
Line 274: | Line 278: | ||
# looping through a dictionary: | # looping through a dictionary: | ||
for key in d: | for key in d: | ||
- | print(key) # print only key | + | print(key) # print only key |
- | print(key, d[key]) # print key and value d[key] | + | print(key, d[key]) # print key and value d[key] |
Line 293: | Line 297: | ||
else: | else: | ||
print('not found') | print('not found') | ||
+ | |||
+ | </code> | ||
+ | |||
+ | <code python> | ||
# counting the number of times a letter appears in a string: | # counting the number of times a letter appears in a string: | ||
Line 317: | Line 325: | ||
**T5 (4p - bonus)** You have a list of numbers. Write a program to show the frequency of each number as the number of times that number is found in the list. | **T5 (4p - bonus)** You have a list of numbers. Write a program to show the frequency of each number as the number of times that number is found in the list. | ||
- | Tip: | + | Hint: |
- | + | * Use dictionaries to keep track of each element | |
- | *Use dictionaries to keep track of each element | + | |
</note> | </note> | ||
**Resources**: | **Resources**: | ||
- | https://www.youtube.com/watch?v=WGlMlS_Yydk | + | * [[http://mathworld.wolfram.com/L2-Norm.html|L^2-Norm]] |
- | + | * [[http://mathworld.wolfram.com/StandardDeviation.html|Standard Deviation]] | |
- | http://mathworld.wolfram.com/L2-Norm.html | + | * [[https://www.youtube.com/watch?v=WGlMlS_Yydk|Apriori Algorithm (Associated Learning) - Fun and Easy Machine Learning]] |
- | http://mathworld.wolfram.com/StandardDeviation.html | ||