This shows you the differences between two versions of the page.
ii:labs:s2:01:tasks:03 [2023/03/18 19:44] florin.stancu |
ii:labs:s2:01:tasks:03 [2024/03/15 13:30] (current) florin.stancu [03. [20p] Making the list] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== 03. Making the list ==== | + | ==== 03. [25p] Making the list ==== |
Solve these subtasks all in the same file (use ''print()'' statements to display the results): | Solve these subtasks all in the same file (use ''print()'' statements to display the results): | ||
Line 9: | Line 9: | ||
Well: | Well: | ||
- | * Print the sorted list (you might need to return to this later and make it right :P); | + | * Sort the list (does it work? if not, why?); |
- | * Filter out all non-numbers in the list (note: those values of the ''int'' type should remain!)... can you make it using **a single line of code**? now it's the time to introduce [[https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions|list comprehensions]]; | + | * Reverse the list (this again? note: save the original one!); |
- | * Print the original list (remember the sort? [[https://stackoverflow.com/questions/2612802/how-do-i-clone-a-list-so-that-it-doesnt-change-unexpectedly-after-assignment|read this answer!]]); | + | * Filter out all non-numbers from the list (i.e., only ''int'' type values should remain)... can you make it using **a single line of code**? now it's the time to introduce [[https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions|list comprehensions]]; |
+ | <note> | ||
+ | Don't know how to check the type of a variable? | ||
+ | [[https://www.google.com/search?q=python+check+type+is+int|LMGTFY]]! | ||
+ | </note> | ||
+ | * Print the original list (remember the first 2 subtasks? [[https://stackoverflow.com/questions/2612802/how-do-i-clone-a-list-so-that-it-doesnt-change-unexpectedly-after-assignment|read this answer!]]); | ||
* Define a function that builds a matrix filled with numbers from 1 to n like the following example:<code python> | * Define a function that builds a matrix filled with numbers from 1 to n like the following example:<code python> | ||
m = [[1, 2, 3, 4], | m = [[1, 2, 3, 4], |