forked from rogerwcpt/python-linq-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinq-conversion.py
51 lines (31 loc) · 1.03 KB
/
linq-conversion.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
import shared
def linq54():
doubles = [1.7, 2.3, 1.9, 4.1, 2.9]
sorted_doubles = sorted(doubles, reverse=True)
doubles_array = list(sorted_doubles)
print("Every other double from highest to lowest:")
d = 0
while d < len(doubles_array):
print(doubles_array[d])
d += 2
def linq55():
words = ["cherry", "apple", "blueberry"]
sorted_words = sorted(words)
word_list = list(sorted_words)
print("The sorted word list:")
shared.printN(word_list)
def linq56():
score_records = [{'Name': "Alice", 'Score': 50},
{'Name': "Bob", 'Score': 40},
{'Name': "Cathy", 'Score': 45}]
score_records_dict = {s['Name']:s['Score'] for s in score_records}
print("Bob's score: %s" % score_records_dict["Bob"])
def linq57():
numbers = [None, 1.0, "two", 3, "four", 5, "six", 7.0]
floats = (n for n in numbers if isinstance(n, float))
print("Numbers stored as floats:")
shared.printN(floats)
linq54()
# linq55()
# linq56()
# linq57()