-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparte3.py
More file actions
76 lines (59 loc) · 2.31 KB
/
parte3.py
File metadata and controls
76 lines (59 loc) · 2.31 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
######################################################
# set
######################################################
# Create a set
# num_set = set([0, 1, 2, 3, 4, 5])
# for n in num_set:
# print(n)
# Cria frozenset
# x = frozenset([1, 2, 3, 4, 5])
# y = frozenset([3, 4, 5, 6, 7])
#use isdisjoint(). Return True if the set has no elements in common with other.
# print(x.isdisjoint(y))
#use difference(). Return a new set with elements in the set that are not in the others.
# print(x.difference(y))
#new set with elements from both x and y
# print(x | y)
######################################################
# # map
# ######################################################
# people = ['Dr. Christopher Brooks', 'Dr. Kevyn Collins-Thompson',
# 'Dr. VG Vinod Vydiswaran', 'Dr. Daniel Romero']
# def split_title_and_name(person):
# p = person.split(" ")
# return p[0] + " " + p[2]
# print(list(map(split_title_and_name, people)))
# print(type(map(split_title_and_name, people)))
######################################################
# # lambda
######################################################
# people = ['Dr. Christopher Brooks', 'Dr. Kevyn Collins-Thompson', 'Dr. VG Vinod Vydiswaran', 'Dr. Daniel Romero']
# def split_title_and_name(person):
# return person.split()[0] + ' ' + person.split()[-1]
#option 1
# for person in people:
# my_func = lambda person:person.split()[0] + ' ' + person.split()[-1]
# print(split_title_and_name(person) == (my_func(person)))
# for person in people:
# print(split_title_and_name(person) == (lambda x: x.split()[0] + ' ' + x.split()[-1])(person))
#option 2
# list(map(split_title_and_name, people)) == list(map(lambda person : person.split()[0] + ' ' + person.split()[-1], people))
######################################################
# comprehension
######################################################
# lista = []
# for n in range(0,1000):
# if n % 2 == 0:
# lista.append(n)
# print(lista)
# lista2 = [n for n in range(0,1000) if n % 2 == 0]
# print(lista2)
# print(lista2 == lista)
# def times_tables():
# lst = []
# for i in range(10):
# for j in range (10):
# lst.append(i*j)
# return lst
# print(times_tables() == [(i*j) for i in range(10) for j in range(10)])
# t = [(i*j) for i in range(10) for j in range(10)]