2017-11-18 16:45:28 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Zad 2. Napisz funkcję even_elements zwracającą listę,
|
|
|
|
która zawiera tylko elementy z list o parzystych indeksach.
|
2017-11-19 15:42:56 +01:00
|
|
|
== identyczne
|
|
|
|
!= rozne
|
|
|
|
and
|
|
|
|
or (malymi literami)
|
2017-11-18 16:45:28 +01:00
|
|
|
"""
|
2017-11-19 15:42:56 +01:00
|
|
|
lista = [5, 7, 9, 0, 10]
|
2017-11-18 16:45:28 +01:00
|
|
|
def even_elements(lista):
|
2017-11-19 15:42:56 +01:00
|
|
|
for i in lista:
|
|
|
|
id = lista.index()
|
|
|
|
if id %2==0:
|
|
|
|
print('parzyste indeksy', even_elements(id))
|
|
|
|
|
|
|
|
l = [99, 44, 33]
|
|
|
|
print(l.index(44))
|
|
|
|
|
|
|
|
def find_element_in_list(element, list_element):
|
|
|
|
try:
|
|
|
|
index_element = list_element.index(element)
|
|
|
|
return index_element
|
|
|
|
except ValueError:
|
|
|
|
return None
|
|
|
|
|
|
|
|
lista = [5, 7, 9, 0, 10]
|
|
|
|
id = lista.index("5")
|
|
|
|
print("lista",[id])
|
|
|
|
|
|
|
|
|
|
|
|
testlist = [1,2,3,5,3,1,2,1,6]
|
|
|
|
for id, value in enumerate(testlist):
|
|
|
|
if id == 3:
|
|
|
|
print(testlist[id])
|
2017-11-18 16:45:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
def tests(f):
|
|
|
|
inputs = [[[1, 2, 3, 4, 5, 6]], [[]], [[41]]]
|
|
|
|
outputs = [[1, 3, 5], [], [41]]
|
|
|
|
|
2017-11-19 15:42:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-18 16:45:28 +01:00
|
|
|
for input, output in zip(inputs, outputs):
|
|
|
|
if f(*input) != output:
|
|
|
|
return "ERROR: {}!={}".format(f(*input), output)
|
|
|
|
break
|
|
|
|
return "TESTS PASSED"
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print(tests(even_elements))
|