[Python] ์ˆœ์ฐจํƒ์ƒ‰
ยท
Algorithm/Python
๋ฆฌ์ŠคํŠธ์—์„œ ํŠน์ •๊ฐ’์„ ์ฐพ์•„ ๊ทธ ๊ฐ’์˜ ์œ„์น˜๋ฅผ ๋Œ๋ ค์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ def search_list(a, x): n = len(a) for i in range(n): if x == a[i]: return i return -1 v = [20, 19, 11, 27, 3] print(search_list(v, 11)) ๊ฒฐ๊ณผ : 2 ์ฒซ ๋ฒˆ์งธ ๊ฐ’๋ถ€ํ„ฐ ์ˆœ์„œ๋Œ€๋กœ ๋น„๊ตํ•œ๋‹ค. ๋งŒ์•ฝ 11์„ ์ฐพ์„ ๊ฒฝ์šฐ ๊ทธ ์œ„์น˜๋ฅผ ๋Œ๋ ค์ค€๋‹ค. *3๋ฒˆ์งธ์ธ ๊ฒƒ ๊ฐ™์ง€๋งŒ 0๋ถ€ํ„ฐ ์ˆซ์ž๋ฅผ ์„ธ๊ธฐ ๋•Œ๋ฌธ์— 2๋ฅผ ๋Œ๋ ค์ค€๋‹ค.