Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- def binary_search(card_list, card):
- low = 0
- high = len(card_list) - 1
- while low <= high:
- mid = (low + high) // 2
- guess = card_list[mid]
- if guess == card:
- print("{0}番目に{1}はあります".format(mid, card))
- return
- elif guess < card:
- low = mid + 1
- else:
- high = mid - 1
- return
- if __name__ == '__main__':
- heart_cards = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
- heart_eight = 'c'
- binary_search(heart_cards, heart_eight)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement