Skip to content

Commit c91dc6f

Browse files
committed
up
1 parent 7e46f17 commit c91dc6f

5 files changed

Lines changed: 2351 additions & 4107 deletions

File tree

lists-tuples.ipynb

Lines changed: 110 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5688,12 +5688,116 @@
56885688
"rev_sorted_list"
56895689
]
56905690
},
5691+
{
5692+
"cell_type": "markdown",
5693+
"id": "76a85ee8",
5694+
"metadata": {},
5695+
"source": [
5696+
"**예제 4**\n",
5697+
"\n",
5698+
"**어구전철**<font size='2'>anagram</font>은 주어진 단어에 사용된 철자의 순서를 변경해서 생성되는 단어를 가리킨다.\n",
5699+
"예를 들어 \"python\"\"thpyon\" 서로 어구전철 관계다.\n",
5700+
"\n",
5701+
"`'python'`, `'thpyon'` 두 문자열이 서로 어구전철임을 확인해주는 코드를 작성하라.\n",
5702+
"\n",
5703+
"힌트: `sorted()` 함수 활용"
5704+
]
5705+
},
5706+
{
5707+
"cell_type": "markdown",
5708+
"id": "adf7bb8d",
5709+
"metadata": {},
5710+
"source": [
5711+
"답:"
5712+
]
5713+
},
5714+
{
5715+
"cell_type": "markdown",
5716+
"id": "4e124dd5",
5717+
"metadata": {},
5718+
"source": [
5719+
"어구전철 관계의 두 단어는 사용하는 문자의 종류와 빈도가 동일하다.\n",
5720+
"따라서 두 문자열에 포함된 문자를 알파벳 순으로 정렬했을 때 동일한 값이 된다.\n",
5721+
"\n",
5722+
"그런데 문자열은 불변자료형이기에 그 자체로 알파벳 순서로 정렬하는 것이 불가능하다.\n",
5723+
"따라서 먼저 `sorted()` 함수를 이용하여 문자열을 문자 단위로 쪼갠 리스트를 정렬한 후에 비교하는 방식을 사용한다.\n",
5724+
"`sorted()` 함수는 문자열에 포함된 알파벳을 크기 순으로 정렬한 리스트를 반환한다."
5725+
]
5726+
},
5727+
{
5728+
"cell_type": "code",
5729+
"execution_count": null,
5730+
"id": "894dd143",
5731+
"metadata": {},
5732+
"outputs": [
5733+
{
5734+
"data": {
5735+
"text/plain": [
5736+
"['h', 'n', 'o', 'p', 't', 'y']"
5737+
]
5738+
},
5739+
"metadata": {},
5740+
"output_type": "display_data"
5741+
}
5742+
],
5743+
"source": [
5744+
"sorted('python')"
5745+
]
5746+
},
5747+
{
5748+
"cell_type": "code",
5749+
"execution_count": null,
5750+
"id": "b076d069",
5751+
"metadata": {},
5752+
"outputs": [
5753+
{
5754+
"data": {
5755+
"text/plain": [
5756+
"['h', 'n', 'o', 'p', 't', 'y']"
5757+
]
5758+
},
5759+
"metadata": {},
5760+
"output_type": "display_data"
5761+
}
5762+
],
5763+
"source": [
5764+
"sorted('thpyon')"
5765+
]
5766+
},
5767+
{
5768+
"cell_type": "markdown",
5769+
"id": "8b2c6d63",
5770+
"metadata": {},
5771+
"source": [
5772+
"이제 주어진 두 단어의 어구전철 여부는 `==` 연산자로 바로 확인할 수 있다."
5773+
]
5774+
},
5775+
{
5776+
"cell_type": "code",
5777+
"execution_count": null,
5778+
"id": "8f34856b",
5779+
"metadata": {},
5780+
"outputs": [
5781+
{
5782+
"data": {
5783+
"text/plain": [
5784+
"True"
5785+
]
5786+
},
5787+
"metadata": {},
5788+
"output_type": "display_data"
5789+
}
5790+
],
5791+
"source": [
5792+
"sorted('python') == sorted('thpyon')"
5793+
]
5794+
},
56915795
{
56925796
"cell_type": "markdown",
56935797
"id": "e3da281b-151f-4fdf-8056-154d9b2bbce3",
56945798
"metadata": {},
56955799
"source": [
5696-
"**예제 4**"
5800+
"**예제 5**"
56975801
]
56985802
},
56995803
{
@@ -5822,7 +5926,7 @@
58225926
"id": "0c2a686d-8b4f-4204-a460-660f657ef1c2",
58235927
"metadata": {},
58245928
"source": [
5825-
"**예제 5**"
5929+
"**예제 6**"
58265930
]
58275931
},
58285932
{
@@ -5912,7 +6016,7 @@
59126016
"id": "39964acd-a859-423f-99bc-e622c28c8e5c",
59136017
"metadata": {},
59146018
"source": [
5915-
"**예제 6**"
6019+
"**예제 7**"
59166020
]
59176021
},
59186022
{
@@ -6340,7 +6444,7 @@
63406444
"id": "c3c758e6-588a-4ef6-84d0-c9681cabc334",
63416445
"metadata": {},
63426446
"source": [
6343-
"**예제 7**"
6447+
"**예제 8**"
63446448
]
63456449
},
63466450
{
@@ -6427,7 +6531,7 @@
64276531
"id": "30e40c30-9632-4edb-96ab-d94916814b09",
64286532
"metadata": {},
64296533
"source": [
6430-
"**예제 8**"
6534+
"**예제 9**"
64316535
]
64326536
},
64336537
{
@@ -6520,4 +6624,4 @@
65206624
},
65216625
"nbformat": 4,
65226626
"nbformat_minor": 5
6523-
}
6627+
}

0 commit comments

Comments
 (0)