-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind_elements.py
49 lines (33 loc) · 977 Bytes
/
find_elements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# This function find elements that bigger then 4 in my_list[]
'''
def find_elements(lst, value):
new_list = []
for element in lst:
if element > value:
new_list.append(element)
return new_list
my_list = [1, 3, 5, 6, 9, 3, 5, 4, 7]
print(find_elements(my_list, 2))
'''
# Find elements <= 22
def find_elements(lst, value):
new_list = []
for element in lst:
if element <= value:
new_list.append(element)
return new_list
my_list = [22, 22.4, 21.9, 2, 1, 0.5]
print(find_elements(my_list, 22))
# Here use extend, extend takes 2 lists
# and appends all of the elements
def find_elements(lst, value):
new_list = []
for element in lst:
if element > value:
new_list.append(element)
new_list.sort()
return new_list
my_list = [2, 3, 4, 6, 122, 3, 0.3]
my_second_list = [3, 4, 9, 0, 333]
my_list.extend(my_second_list)
print(find_elements(my_list, 7))