Skip to content

Commit 281837b

Browse files
authored
String in python
1 parent 2b9f471 commit 281837b

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

String_Assignment.ipynb

+31-16
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
{
105105
"data": {
106106
"text/plain": [
107-
"<reversed at 0x1aced3ae370>"
107+
"<reversed at 0x20e44f1e2b0>"
108108
]
109109
},
110110
"execution_count": 6,
@@ -230,7 +230,7 @@
230230
{
231231
"data": {
232232
"text/plain": [
233-
"'<reversed object at 0x000001ACED4181F0>'"
233+
"'<reversed object at 0x0000020E45F561C0>'"
234234
]
235235
},
236236
"execution_count": 12,
@@ -444,8 +444,8 @@
444444
"name": "stdout",
445445
"output_type": "stream",
446446
"text": [
447-
"1842226524928\n",
448-
"1842226515520\n"
447+
"2260326522192\n",
448+
"2260326522352\n"
449449
]
450450
}
451451
],
@@ -2720,30 +2720,45 @@
27202720
"execution_count": 131,
27212721
"id": "d9e6c264",
27222722
"metadata": {},
2723-
"outputs": [],
2723+
"outputs": [
2724+
{
2725+
"name": "stdout",
2726+
"output_type": "stream",
2727+
"text": [
2728+
"[2, 3, 5, 7]\n"
2729+
]
2730+
}
2731+
],
27242732
"source": [
27252733
"#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)"
27272738
]
27282739
},
27292740
{
27302741
"cell_type": "code",
27312742
"execution_count": 132,
27322743
"id": "2abee47f",
27332744
"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+
],
27352754
"source": [
27362755
"#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)"
27382761
]
2739-
},
2740-
{
2741-
"cell_type": "code",
2742-
"execution_count": null,
2743-
"id": "e765c825",
2744-
"metadata": {},
2745-
"outputs": [],
2746-
"source": []
27472762
}
27482763
],
27492764
"metadata": {

0 commit comments

Comments
 (0)