# 리μ€νΈ.index(x)
# λ°μ΄ν° xμ μμΉ λ°ν
nums_list = [1,2,3,3,3,5,6,8,9]
nums_tuple = (1,2,3,3,3,5,6,8,9)
nums_set = {1,2,3,5,6,8,9}
print(nums_list.index(2)) # 1
print(nums_list.index(3)) # 2
# -> μ°Ύκ³ μνλ λ°μ΄ν°κ° μ¬λ¬κ° μ‘΄μ¬ν κ²½μ°, κ°μ₯ μμ μμΉ κ° λ°ν
print(nums_tuple.index(2)) # 1
print(nums_tuple.index(3)) # 2
#print(nums_set.index(2)) #AttributeError: 'set' object has no attribute 'index'
#setμλ£νμ μ¬μ© x
#λ¬Έμμ΄μμ μ¬μ©
str = 'kangminheee'
print(str.index('k')) #0
print(str.index('h')) #7
print(str.index('i')) #5
#print(str.index('l')) μλ κ±Έ μ°ΎμΌλ©΄ error
print(str.index('e')) #8 -> μ¬λ¬κ°λ©΄ μ μΌ μ²«λ²μ§Έκ² λ°ν
print(str.find('e')) #8 -> find()λ index()μ κ°μ κΈ°λ₯μ κ°μ§ ν¨μ
print(str.rfind('e')) #10 -> μ¬λ¬κ°μ€ κ°μ₯ μ€λ₯Έμͺ½ κ² λ°ν
π binary searchμ λΉκ΅
μ
λ ₯κ°μ λ²μκ° ν¬μ§ μμ κ²½μ°μλ μλμ°¨μ΄κ° λ³λ‘ X. μ€νλ € index( )λ©μλκ° λ λΉ λ¦
νμ§λ§ μ
λ ₯κ°μ λ²μκ° μ»€μ§λ©΄ 컀μ§μλ‘ index() λ©μλμ μλλ λλ €μ§μ§λ§, binary searchμ κ²½μ° νμ μΌμ ν μλλ₯Ό 보μ
< κ²°λ‘ > μ λ ₯κ°μ λ²μλ₯Ό λͺ¨λ₯Ό κ²½μ°μλ binary searchλ₯Ό μ¬μ©νμ!