Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ewis:laboratoare:02 [2021/03/17 16:56]
alexandru.predescu [Data Structures]
ewis:laboratoare:02 [2023/03/15 17:40] (current)
alexandru.predescu [Data Structures]
Line 24: Line 24:
 </​code>​ </​code>​
  
-**T1 (2p)** Having a list of numbers, write a function to calculate the sum of all elements in the list.+**T1 (1p)** Having a list of numbers, write a function to calculate the sum of all elements in the list.
 Tip: List given as input, using a for loop Tip: List given as input, using a for loop
 </​note>​ </​note>​
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 85: Line 88:
 **T2.1 (1p)** Use the functions to compute the arithmetic mean, weighted arithmetic mean, variance, standard deviation and L2-norm normalization of the list **T2.1 (1p)** Use the functions to compute the arithmetic mean, weighted arithmetic mean, variance, standard deviation and L2-norm normalization of the list
  
-**T2.2 (1p)** Implement the functions using list comprehension,​ without using for loops+**T2.2 (2p)** Implement the functions using list comprehension,​ without using for loops
  
 </​note>​ </​note>​
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 122: Line 125:
 </​code>​ </​code>​
  
-**T3 (2p)** Create two Python files (.py) as in the example. Run the program //main.py// and check the output in the console+**T3 (2p)** Create two Python files (.py) in the same project folder, ​as shown in the example. Run the program //main.py// and check the output in the console
  
 </​note>​ </​note>​
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 
  
  
  
ewis/laboratoare/02.1615993010.txt.gz · Last modified: 2021/03/17 16:56 by alexandru.predescu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0