|
87 | 87 | "colab_type": "text" |
88 | 88 | }, |
89 | 89 | "source": [ |
| 90 | + "___\n", |
90 | 91 | "# Python Lists Comprehension\n", |
91 | 92 | "\n", |
92 | 93 | "Sintaxe básica:\n", |
|
137 | 138 | "colab_type": "code", |
138 | 139 | "colab": { |
139 | 140 | "base_uri": "https://localhost:8080/", |
140 | | - "height": 35 |
| 141 | + "height": 34 |
141 | 142 | }, |
142 | 143 | "outputId": "7f8f2f47-009a-4e17-b8a0-f36ad8219355" |
143 | 144 | }, |
|
171 | 172 | "import numpy as np\n", |
172 | 173 | "\n", |
173 | 174 | "np.random.seed(20111974)\n", |
174 | | - "l_FloatNumbers= [np.random.random() for _ in range(5)]" |
| 175 | + "l_FloatNumbers= [np.random.randint(0, 10) for _ in range(5)]" |
175 | 176 | ], |
176 | 177 | "execution_count": 0, |
177 | 178 | "outputs": [] |
|
181 | 182 | "metadata": { |
182 | 183 | "id": "giOtZF37MeIv", |
183 | 184 | "colab_type": "code", |
184 | | - "outputId": "f1d9984f-e495-477f-9a4d-6b300ca56ef2", |
| 185 | + "outputId": "d5894cc4-ba0a-40f0-a47f-3c307c15c6e7", |
185 | 186 | "colab": { |
186 | 187 | "base_uri": "https://localhost:8080/", |
187 | | - "height": 101 |
| 188 | + "height": 34 |
188 | 189 | } |
189 | 190 | }, |
190 | 191 | "source": [ |
191 | 192 | "l_FloatNumbers" |
192 | 193 | ], |
193 | | - "execution_count": 0, |
| 194 | + "execution_count": 7, |
194 | 195 | "outputs": [ |
195 | 196 | { |
196 | 197 | "output_type": "execute_result", |
197 | 198 | "data": { |
198 | 199 | "text/plain": [ |
199 | | - "[0.5309723295184019,\n", |
200 | | - " 0.569656260808191,\n", |
201 | | - " 0.5425293780522449,\n", |
202 | | - " 0.6547840853457134,\n", |
203 | | - " 0.8570845590847208]" |
| 200 | + "[8, 8, 2, 8, 9]" |
204 | 201 | ] |
205 | 202 | }, |
206 | 203 | "metadata": { |
207 | 204 | "tags": [] |
208 | 205 | }, |
209 | | - "execution_count": 4 |
| 206 | + "execution_count": 7 |
210 | 207 | } |
211 | 208 | ] |
212 | 209 | }, |
|
225 | 222 | "metadata": { |
226 | 223 | "id": "tANHZTvzP0JT", |
227 | 224 | "colab_type": "code", |
228 | | - "outputId": "fb45b38a-25e0-48e4-9e63-72d10059875d", |
| 225 | + "outputId": "689fd6d1-9578-4087-e80b-cc8714856916", |
229 | 226 | "colab": { |
230 | 227 | "base_uri": "https://localhost:8080/", |
231 | 228 | "height": 34 |
|
240 | 237 | "\n", |
241 | 238 | "print(l_Quadrado)" |
242 | 239 | ], |
243 | | - "execution_count": 0, |
| 240 | + "execution_count": 8, |
244 | 241 | "outputs": [ |
245 | 242 | { |
246 | 243 | "output_type": "stream", |
|
314 | 311 | "source": [ |
315 | 312 | "l_Lista_A = [1, 2, 3, 4]\n", |
316 | 313 | "l_Lista_B = [2, 3, 4, 5]\n", |
317 | | - "\n", |
318 | 314 | "l_Comum = []\n", |
319 | 315 | "\n", |
320 | 316 | "for x in l_Lista_A:\n", |
|
350 | 346 | "metadata": { |
351 | 347 | "id": "mNt-OixCQ1Bg", |
352 | 348 | "colab_type": "code", |
353 | | - "outputId": "eff9e1fd-27cf-4480-df34-f46569907bbd", |
| 349 | + "outputId": "f187556a-184d-4f15-e94c-ee4d0ddf99a9", |
354 | 350 | "colab": { |
355 | 351 | "base_uri": "https://localhost:8080/", |
356 | 352 | "height": 34 |
|
361 | 357 | "l_Lista_B = [2, 3, 4, 5]\n", |
362 | 358 | "\n", |
363 | 359 | "l_Comum = [x for x in l_Lista_A for y in l_Lista_B if x == y]\n", |
364 | | - "\n", |
365 | 360 | "print(l_Comum)" |
366 | 361 | ], |
367 | | - "execution_count": 0, |
| 362 | + "execution_count": 9, |
368 | 363 | "outputs": [ |
369 | 364 | { |
370 | 365 | "output_type": "stream", |
|
630 | 625 | "metadata": { |
631 | 626 | "id": "ErZoaMpe5mgE", |
632 | 627 | "colab_type": "code", |
633 | | - "outputId": "78cc4602-20f0-4bad-82de-a3ce1af72fb9", |
| 628 | + "outputId": "97745ea1-75ee-49da-e33f-dfd052cab4b1", |
634 | 629 | "colab": { |
635 | 630 | "base_uri": "https://localhost:8080/", |
636 | 631 | "height": 34 |
|
643 | 638 | "\n", |
644 | 639 | "np.random.seed(20111974)\n", |
645 | 640 | "l_Fahrenheit= [np.random.randint(10, 80, 10)]\n", |
646 | | - "l_Farenheit" |
| 641 | + "l_Fahrenheit" |
647 | 642 | ], |
648 | | - "execution_count": 0, |
| 643 | + "execution_count": 11, |
649 | 644 | "outputs": [ |
650 | 645 | { |
651 | 646 | "output_type": "execute_result", |
|
657 | 652 | "metadata": { |
658 | 653 | "tags": [] |
659 | 654 | }, |
660 | | - "execution_count": 25 |
| 655 | + "execution_count": 11 |
661 | 656 | } |
662 | 657 | ] |
663 | 658 | }, |
|
666 | 661 | "metadata": { |
667 | 662 | "id": "MetowzHE5fYS", |
668 | 663 | "colab_type": "code", |
669 | | - "outputId": "8449425f-2ce8-46a0-b120-d5f28d1ead5f", |
| 664 | + "outputId": "25b50020-04e1-4fc2-b670-a43626e2c3b4", |
670 | 665 | "colab": { |
671 | 666 | "base_uri": "https://localhost:8080/", |
672 | 667 | "height": 67 |
673 | 668 | } |
674 | 669 | }, |
675 | 670 | "source": [ |
676 | | - "l_Celsius= [(x-32)*(5/9) for x in l_Farenheit]\n", |
| 671 | + "l_Celsius= [(x-32)*(5/9) for x in l_Fahrenheit]\n", |
677 | 672 | "l_Celsius" |
678 | 673 | ], |
679 | | - "execution_count": 0, |
| 674 | + "execution_count": 12, |
680 | 675 | "outputs": [ |
681 | 676 | { |
682 | 677 | "output_type": "execute_result", |
|
690 | 685 | "metadata": { |
691 | 686 | "tags": [] |
692 | 687 | }, |
693 | | - "execution_count": 26 |
| 688 | + "execution_count": 12 |
694 | 689 | } |
695 | 690 | ] |
696 | 691 | }, |
|
778 | 773 | "metadata": { |
779 | 774 | "id": "LX7oPa2L-lkK", |
780 | 775 | "colab_type": "code", |
781 | | - "outputId": "703f76f8-55c0-48b7-c0e0-8dfecb0f5894", |
| 776 | + "outputId": "f0cff845-3077-4e4f-9740-b04c4975c27b", |
782 | 777 | "colab": { |
783 | 778 | "base_uri": "https://localhost:8080/", |
784 | 779 | "height": 34 |
|
787 | 782 | "source": [ |
788 | 783 | "[(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]" |
789 | 784 | ], |
790 | | - "execution_count": 0, |
| 785 | + "execution_count": 13, |
791 | 786 | "outputs": [ |
792 | 787 | { |
793 | 788 | "output_type": "execute_result", |
|
799 | 794 | "metadata": { |
800 | 795 | "tags": [] |
801 | 796 | }, |
802 | | - "execution_count": 28 |
| 797 | + "execution_count": 13 |
803 | 798 | } |
804 | 799 | ] |
805 | 800 | }, |
|
0 commit comments