l = [1,2,3] l i = l.__iter__() i print(i.__next__()) print(i.__next__()) print(i.__next__()) i.__next__() for n in l: print(n) list(map(lambda x: x.upper(), ['cat', 'dog', 'cow'])) list(filter(lambda x: 'o' in x, ['cat', 'dog', 'cow'])) from functools import reduce numbers = [11,22,33,1] reduce(lambda x,y: x if x > y else y, numbers) ids = ['id1', 'id2', 'id30', 'id3', 'id22', 'id100'] ids sorted(ids) sorted(ids, key=lambda x: int(x[2:])) from heapq import nsmallest, nlargest nlargest(3, ids, key=lambda x: int(x[2:])) nsmallest(3, ids, key=lambda x: int(x[2:]))
numbers = [1,45,672,7265,16] sorted_numbers = sorted(numbers, key=lambda x: x % 10) print(sorted_numbers) from functools import reduce codes = ['JPID', 'JJJPPP', 'XXX', 'JDU'] print(reduce(lambda a, b: a if len(a) > len(b) else b, codes)) capitals =['Rome', 'Paris', 'Madrid'] cities = ['Rome', 'Napoli', 'Rimini', 'Paris', 'Barcelona', 'Madrid', 'Marceille'] print(list(filter(lambda c: c not in capitals, cities)))