Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Nod:
- def __init__(self, e):
- self.e = e
- self.urm = None
- class Lista:
- def __init__(self):
- self.prim = None
- '''
- crearea unei liste din valori citite pana la 0
- '''
- def creareLista():
- lista = Lista()
- lista.prim = creareLista_rec()
- return lista
- def creareLista_rec():
- x = int(input("x="))
- if x == 0:
- return None
- else:
- nod = Nod(x)
- nod.urm = creareLista_rec()
- return nod
- '''
- tiparirea elementelor unei liste
- '''
- '''
- def tipar(lista):
- tipar_rec(lista.prim)
- def tipar_rec(nod):
- if nod != None:
- print(nod.e)
- tipar_rec(nod.urm)
- '''
- '''
- program pentru test
- '''
- def number(list):
- if list == []:
- return 0
- elif list[0] % 2 == 0:
- return list[0] + number(list[1:])
- elif list[0] % 2 != 0:
- return -list[0] + number(list[1:])
- newList = []
- def difference(list1, list2):
- if list1 == [] and newList == []:
- return list2
- elif list2 == [] and newList == []:
- return list1
- elif list1 == [] :
- #return list2
- return newList
- elif list2 == []:
- #return list1
- return newList
- elif list1[0] == list2[0]:
- return difference(list1[1:], list2[1:])
- elif list1[0] > list2[0]:
- newList.insert(0, list2[0])
- return difference(list1, list2[1:])
- elif list1[0] < list2[0]:
- newList.insert(0, list1[0])
- return difference(list1[1:], list2)
- def main():
- #list = creareLista()
- listtttttt = []
- list = [1, 2, 3, 4, 5, 6]
- print(number(list))
- list1 = [1, 2, 3, 4, 5, 6]
- list2 = [1, 3, 6]
- #list2 = []
- print(difference(list1, list2))
- #tipar(list)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement