-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlinq-partitions.py
123 lines (82 loc) · 2.96 KB
/
linq-partitions.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import shared
import functions
import datetime
from types import SimpleNamespace
from itertools import takewhile
from itertools import dropwhile
def linq20():
numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0]
first3_numbers = numbers[:3]
print("First 3 numbers:")
shared.printN(first3_numbers)
def linq21():
customers = shared.getCustomerList()
order_greater_than_date = ((cust, order)
for cust in customers
for order in cust.Orders
if cust.Region == "WA")
orders = [SimpleNamespace(customer_id=x[0].CustomerID,
order_id=x[1].OrderID,
orderDate=x[1].OrderDate)
for x in order_greater_than_date]
first_3_orders = orders[:3]
print("First 3 orders in WA:")
shared.print_namespace(first_3_orders)
def linq22():
numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0]
all_but_first4_numbers = numbers[4:]
print("All but first 4 numbers:")
shared.printN(all_but_first4_numbers)
def linq23():
customers = shared.getCustomerList()
order_greater_than_date = ((cust, order)
for cust in customers
for order in cust.Orders
if cust.Region == "WA")
orders = [SimpleNamespace(customer_id=x[0].CustomerID,
order_id=x[1].OrderID,
orderDate=x[1].OrderDate)
for x in order_greater_than_date]
all_but_first2 = orders[2:]
print("All but first 2 orders in WA:")
shared.print_namespace(all_but_first2)
def linq24():
numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0]
first_numbers_less_than6 = takewhile(lambda x: x < 6, numbers)
print("First numbers less than 6:")
shared.printN(first_numbers_less_than6)
def linq25():
numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0]
index = 0
def digit_greater_equal_to_index(digit):
nonlocal index
result = digit >= index
index += 1
return result
first_small_numbers = takewhile(digit_greater_equal_to_index, numbers)
print("First numbers not less than their position:")
shared.printN(first_small_numbers)
def linq26():
numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0]
all_but_first3_numbers = dropwhile(lambda n: n % 3 != 0, numbers)
print("All elements starting from first element divisible by 3:")
shared.printN(all_but_first3_numbers)
def linq27():
numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0]
index = 0
def digit_greater_equal_to_index(digit):
nonlocal index
result = digit >= index
index += 1
return result
later_numbers = dropwhile(digit_greater_equal_to_index, numbers)
print("All elements starting from first element less than its position:")
shared.printN(later_numbers)
# linq20()
# linq21()
# linq22()
# linq23()
# linq24()
# linq25()
# linq26()
# linq27()