Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3e73505

Browse files
committed
finish all(), starting any()
1 parent f665b67 commit 3e73505

File tree

5 files changed

+561
-0
lines changed

5 files changed

+561
-0
lines changed
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# all(iterable)\n",
8+
"\n",
9+
"Returns `True` if all elements of the iterable are true (or if the iterable is empty):"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 1,
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"False\n"
22+
]
23+
}
24+
],
25+
"source": [
26+
"mixed = [True, False, True]\n",
27+
"print(all(mixed))"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": 2,
33+
"metadata": {},
34+
"outputs": [
35+
{
36+
"name": "stdout",
37+
"output_type": "stream",
38+
"text": [
39+
"True\n"
40+
]
41+
}
42+
],
43+
"source": [
44+
"trues = [True, True, True]\n",
45+
"print(all(trues))"
46+
]
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"metadata": {},
51+
"source": [
52+
"You can make use of list/dict/set comprehension as the `iterable` for the `all()` function. This\n",
53+
"is what makes it more powerful. You usually aren't just given a list of booleans in practice:"
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": 5,
59+
"metadata": {},
60+
"outputs": [
61+
{
62+
"name": "stdout",
63+
"output_type": "stream",
64+
"text": [
65+
"False\n"
66+
]
67+
}
68+
],
69+
"source": [
70+
"nums = list(range(-5, 5))\n",
71+
"\n",
72+
"# Check if every number in list is positive\n",
73+
"print(all(number > 0 for number in nums))"
74+
]
75+
},
76+
{
77+
"cell_type": "markdown",
78+
"metadata": {},
79+
"source": [
80+
"Furthermore, you can use this to check for things such as, if a list contains any bad/null values:"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": 11,
86+
"metadata": {},
87+
"outputs": [
88+
{
89+
"name": "stdout",
90+
"output_type": "stream",
91+
"text": [
92+
"True\n"
93+
]
94+
}
95+
],
96+
"source": [
97+
"# Personal Info Form\n",
98+
"# [First Name, Last Name, Email, Phone Number]\n",
99+
"good_values = [\"Ryan\", \"McCormick\", \"rmccorm4@binghamton.edu\", \"123-456-7890\"]\n",
100+
"print(all(x is not None for x in good_values))"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": 12,
106+
"metadata": {},
107+
"outputs": [
108+
{
109+
"name": "stdout",
110+
"output_type": "stream",
111+
"text": [
112+
"False\n"
113+
]
114+
}
115+
],
116+
"source": [
117+
"# If someone doesn't fill in all the fields of the form\n",
118+
"missing_values = [\"Guy\", \"Fawkes\", \"anonymous@4chan\", None]\n",
119+
"print(all(x is not None for x in missing_values))"
120+
]
121+
},
122+
{
123+
"cell_type": "markdown",
124+
"metadata": {},
125+
"source": [
126+
"You can also use it to check for empty strings(''):"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": 16,
132+
"metadata": {},
133+
"outputs": [
134+
{
135+
"name": "stdout",
136+
"output_type": "stream",
137+
"text": [
138+
"False\n"
139+
]
140+
}
141+
],
142+
"source": [
143+
"strings = [\"hello\", \"\"]\n",
144+
"print(all(strings))"
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": 17,
150+
"metadata": {},
151+
"outputs": [
152+
{
153+
"name": "stdout",
154+
"output_type": "stream",
155+
"text": [
156+
"True\n"
157+
]
158+
}
159+
],
160+
"source": [
161+
"strings2 = [\"hello\", \"world\"]\n",
162+
"print(all(strings2))"
163+
]
164+
}
165+
],
166+
"metadata": {
167+
"kernelspec": {
168+
"display_name": "Python 3",
169+
"language": "python",
170+
"name": "python3"
171+
},
172+
"language_info": {
173+
"codemirror_mode": {
174+
"name": "ipython",
175+
"version": 3
176+
},
177+
"file_extension": ".py",
178+
"mimetype": "text/x-python",
179+
"name": "python",
180+
"nbconvert_exporter": "python",
181+
"pygments_lexer": "ipython3",
182+
"version": "3.6.4"
183+
}
184+
},
185+
"nbformat": 4,
186+
"nbformat_minor": 2
187+
}

‎built_in_functions/all.ipynb‎

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# all(iterable)\n",
8+
"\n",
9+
"Returns `True` if all elements of the iterable are true (or if the iterable is empty):"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 1,
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"False\n"
22+
]
23+
}
24+
],
25+
"source": [
26+
"mixed = [True, False, True]\n",
27+
"print(all(mixed))"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": 2,
33+
"metadata": {},
34+
"outputs": [
35+
{
36+
"name": "stdout",
37+
"output_type": "stream",
38+
"text": [
39+
"True\n"
40+
]
41+
}
42+
],
43+
"source": [
44+
"trues = [True, True, True]\n",
45+
"print(all(trues))"
46+
]
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"metadata": {},
51+
"source": [
52+
"You can make use of list/dict/set comprehension as the `iterable` for the `all()` function. This\n",
53+
"is what makes it more powerful. You usually aren't just given a list of booleans in practice:"
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": 5,
59+
"metadata": {},
60+
"outputs": [
61+
{
62+
"name": "stdout",
63+
"output_type": "stream",
64+
"text": [
65+
"False\n"
66+
]
67+
}
68+
],
69+
"source": [
70+
"nums = list(range(-5, 5))\n",
71+
"\n",
72+
"# Check if every number in list is positive\n",
73+
"print(all(number > 0 for number in nums))"
74+
]
75+
},
76+
{
77+
"cell_type": "markdown",
78+
"metadata": {},
79+
"source": [
80+
"Furthermore, you can use this to check for things such as, if a list contains any bad/null values:"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": 11,
86+
"metadata": {},
87+
"outputs": [
88+
{
89+
"name": "stdout",
90+
"output_type": "stream",
91+
"text": [
92+
"True\n"
93+
]
94+
}
95+
],
96+
"source": [
97+
"# Personal Info Form\n",
98+
"# [First Name, Last Name, Email, Phone Number]\n",
99+
"good_values = [\"Ryan\", \"McCormick\", \"rmccorm4@binghamton.edu\", \"123-456-7890\"]\n",
100+
"print(all(x is not None for x in good_values))"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": 12,
106+
"metadata": {},
107+
"outputs": [
108+
{
109+
"name": "stdout",
110+
"output_type": "stream",
111+
"text": [
112+
"False\n"
113+
]
114+
}
115+
],
116+
"source": [
117+
"# If someone doesn't fill in all the fields of the form\n",
118+
"missing_values = [\"Guy\", \"Fawkes\", \"anonymous@4chan\", None]\n",
119+
"print(all(x is not None for x in missing_values))"
120+
]
121+
},
122+
{
123+
"cell_type": "markdown",
124+
"metadata": {},
125+
"source": [
126+
"You can also use it to check for empty strings(''):"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": 16,
132+
"metadata": {},
133+
"outputs": [
134+
{
135+
"name": "stdout",
136+
"output_type": "stream",
137+
"text": [
138+
"False\n"
139+
]
140+
}
141+
],
142+
"source": [
143+
"strings = [\"hello\", \"\"]\n",
144+
"print(all(strings))"
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": 17,
150+
"metadata": {},
151+
"outputs": [
152+
{
153+
"name": "stdout",
154+
"output_type": "stream",
155+
"text": [
156+
"True\n"
157+
]
158+
}
159+
],
160+
"source": [
161+
"strings2 = [\"hello\", \"world\"]\n",
162+
"print(all(strings2))"
163+
]
164+
}
165+
],
166+
"metadata": {
167+
"kernelspec": {
168+
"display_name": "Python 3",
169+
"language": "python",
170+
"name": "python3"
171+
},
172+
"language_info": {
173+
"codemirror_mode": {
174+
"name": "ipython",
175+
"version": 3
176+
},
177+
"file_extension": ".py",
178+
"mimetype": "text/x-python",
179+
"name": "python",
180+
"nbconvert_exporter": "python",
181+
"pygments_lexer": "ipython3",
182+
"version": "3.6.4"
183+
}
184+
},
185+
"nbformat": 4,
186+
"nbformat_minor": 2
187+
}

‎built_in_functions/all.py‎

Whitespace-only changes.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /