|
104 | 104 | { |
105 | 105 | "data": { |
106 | 106 | "text/plain": [ |
107 | | - "<reversed at 0x1aced3ae370>" |
| 107 | + "<reversed at 0x20e44f1e2b0>" |
108 | 108 | ] |
109 | 109 | }, |
110 | 110 | "execution_count": 6, |
|
230 | 230 | { |
231 | 231 | "data": { |
232 | 232 | "text/plain": [ |
233 | | - "'<reversed object at 0x000001ACED4181F0>'" |
| 233 | + "'<reversed object at 0x0000020E45F561C0>'" |
234 | 234 | ] |
235 | 235 | }, |
236 | 236 | "execution_count": 12, |
|
444 | 444 | "name": "stdout", |
445 | 445 | "output_type": "stream", |
446 | 446 | "text": [ |
447 | | - "1842226524928\n", |
448 | | - "1842226515520\n" |
| 447 | + "2260326522192\n", |
| 448 | + "2260326522352\n" |
449 | 449 | ] |
450 | 450 | } |
451 | 451 | ], |
|
2720 | 2720 | "execution_count": 131, |
2721 | 2721 | "id": "d9e6c264", |
2722 | 2722 | "metadata": {}, |
2723 | | - "outputs": [], |
| 2723 | + "outputs": [ |
| 2724 | + { |
| 2725 | + "name": "stdout", |
| 2726 | + "output_type": "stream", |
| 2727 | + "text": [ |
| 2728 | + "[2, 3, 5, 7]\n" |
| 2729 | + ] |
| 2730 | + } |
| 2731 | + ], |
2724 | 2732 | "source": [ |
2725 | 2733 | "#Create a list of only the prime numbers from a given list code and list comprehesnion\n", |
2726 | | - "numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" |
| 2734 | + "numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n", |
| 2735 | + "\n", |
| 2736 | + "prime_numbers = [num for num in numbers if all(num % i != 0 for i in range(2, int(num**0.5) + 1)) and num > 1]\n", |
| 2737 | + "print(prime_numbers)" |
2727 | 2738 | ] |
2728 | 2739 | }, |
2729 | 2740 | { |
2730 | 2741 | "cell_type": "code", |
2731 | 2742 | "execution_count": 132, |
2732 | 2743 | "id": "2abee47f", |
2733 | 2744 | "metadata": {}, |
2734 | | - "outputs": [], |
| 2745 | + "outputs": [ |
| 2746 | + { |
| 2747 | + "name": "stdout", |
| 2748 | + "output_type": "stream", |
| 2749 | + "text": [ |
| 2750 | + "[(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)]\n" |
| 2751 | + ] |
| 2752 | + } |
| 2753 | + ], |
2735 | 2754 | "source": [ |
2736 | 2755 | "#Create a list of all the possible combinations of 2 elements from a list.\n", |
2737 | | - "numbers = [1, 2, 3, 4, 5]" |
| 2756 | + "from itertools import combinations\n", |
| 2757 | + "\n", |
| 2758 | + "numbers = [1, 2, 3, 4, 5]\n", |
| 2759 | + "combinations_list = list(combinations(numbers, 2))\n", |
| 2760 | + "print(combinations_list)" |
2738 | 2761 | ] |
2739 | | - }, |
2740 | | - { |
2741 | | - "cell_type": "code", |
2742 | | - "execution_count": null, |
2743 | | - "id": "e765c825", |
2744 | | - "metadata": {}, |
2745 | | - "outputs": [], |
2746 | | - "source": [] |
2747 | 2762 | } |
2748 | 2763 | ], |
2749 | 2764 | "metadata": { |
|
0 commit comments