Informatics2-2021/Lab02
(Új oldal, tartalma: „= Exercises = == List first == Write a python program that returns the first element of a list, if there is any, and <code>None</code> is the list is empty. The progr…”) |
|||
1. sor: | 1. sor: | ||
+ | [[Informatics2-2021|Home]] | ||
= Exercises = | = Exercises = | ||
A lap jelenlegi, 2021. március 19., 00:38-kori változata
Tartalomjegyzék |
Exercises
List first
Write a python program that returns the first element of a list, if there is any, and None
is the list is empty.
The program should return the first element or a special None
value.
List end
Write a program that returns the last c-part of a list!
If the list is shorter than c then return a None
value. Otherwise return the list of the last c elements.
Perfect numbers
Write a program which evaluates whether a number is perfect.
Separate
Let L be a list of numbers, write a function that separates its elements into two lists: one for positive and one for non-positive elements. For example
L = [-1, 2, 5, -2, 3, -4, -5, 2, -2, 0, 5, 5, 6, 3, -3]
Then the result should be two lists.
Elmax
Write a program that finds the largest value in a list and returns the value.
Argmax
Write a program that finds the largest value in a list and returns the index of that element.
The function should be called argmax
, should have one parameter: l the list of numbers.
The function should return the index of the largest element. For example [3, 2, 1]
should result 0.
Multiply
We have two parameters: a list of numbers l and an additional number k. The output should be a list where every number is k times the corresponding number in l.
Remove Duplicate
Write a python program that remove any duplicate value in a list and return a new list with contains no duplicate.
Intersect
Given two lists. Write a python program that returns true if there is the same value in both lists and returns false otherwise.
Odd Component
Given a list. write a python program which takes all odd values in the list and returns the odd list.