[파일명:  testStringFindInList.py]------------------------------------------------
# coding=ms949

import sys

def find(arr, s):
    for i in range(0, len(arr)):
     if arr[i].find(s) >= 0:
      return i
    return -1;

def printArray(arr):
    sys.stdout.write("[")
    for i in range(0, len(arr) - 1):
         sys.stdout.write(arr[i] + ", ")
    if len(arr) > 0:
        sys.stdout.write(arr[len(arr) - 1])
    print("]")

words = ["하나", "둘", "셋", "넷", "다섯", "여섯"]

sys.stdout.write("list: ")
printArray(words)
where = find(words, "셋")
if where > 0:
    sys.stdout.write("발견!  ")
    print("Next word of 셋 in list: " + words[where+1])

print("Sorting...")
words.sort()

sys.stdout.write("list: ")
printArray(words)
where = find(words, "셋")
if where > 0:
    sys.stdout.write("발견!  ")
    print("Next word of 셋 in list: " + words[where+1])
------------------------------------------------


실행> python testStringFindInList.py
list: [하나, 둘, 셋, 넷, 다섯, 여섯]
발견!  Next word of 셋 in list: 넷
Sorting...
list: [넷, 다섯, 둘, 셋, 여섯, 하나]
발견!  Next word of 셋 in list: 여섯



크리에이티브 커먼즈 라이선스
Creative Commons License

Posted by Scripter
,