-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path021-all.py
More file actions
43 lines (36 loc) · 1.3 KB
/
Copy path021-all.py
File metadata and controls
43 lines (36 loc) · 1.3 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
"""
Return True if all elements in iterable are true
------------------------------------------------
Input (iterable) iterable object
Return (boolean) True, when:
- all items are true
- object is empty
"""
# List contains elements
cars = ["Audi", "BMW", "Chrysler", "Dodge"]
all_cars = all(cars)
print('Object: {}\nAll: {}'.format(cars, all_cars))
# Empty list
empty_list = []
all_empty_list = all(empty_list)
print('\nObject: {}\nAll: {}'.format(empty_list, all_empty_list))
# Tuple
test_tuple = (0, 0, 1)
all_test_tuple = all(test_tuple)
print('\nObject: {}\nAll: {}'.format(test_tuple, all_test_tuple))
# Tuple 2
test_tuple_2 = (25, 25, 25)
all_test_tuple_2 = all(test_tuple_2)
print('\nObject: {}\nAll: {}'.format(test_tuple_2, all_test_tuple_2))
# Dictionary
dictionary = {"name": "Alice", "age": "30"}
all_dictionary = all(dictionary)
print('\nObject: {}\nAll: {}'.format(dictionary, all_dictionary))
# Dictionary 2
dictionary_2 = {"name": True, "age": False}
all_dictionary_2 = all(dictionary_2)
print('\nObject: {}\nAll: {}'.format(dictionary_2, all_dictionary_2))
# Dictionary 3
dictionary_3 = {0: "Alice", 1: "name"}
all_dictionary_3 = all(dictionary_3)
print('\nObject: {}\nAll: {}'.format(dictionary_3, all_dictionary_3))