편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2019.04.18

    파이썬 find 함수 메소드 rfind 쓰지 않고 마지막 문자열 하나만 찾기


    def findLast(filename,key):
    
        infile = open(filename,"r")  
        outfile = open("result.txt","w")
        text = infile.read()
        position = text.find(key)
        if position == -1:
            outfile.write(key + " is not found.\n")
        else:
            outfile.write(key + " is at " + str(position) + ".\n")
        outfile.close()
        infile.close()
        print("Done")
    

    위 함수는 첫 번째 문자열만 찾는 함수입니다. 혹시 여기서 while 함수를 사용해서 마지막 문자열만 찾는 함수는 어떻게 만들 수 있을까요 ㅠ

  • 프로필 블루헙님의 편집
    날짜2019.04.17

    파이썬 find 함수 메소드 rfind 쓰지 않고 마지막 문자열 하나만 찾기


    def findLast(filename,key):

    infile = open(filename,"r")  
    outfile = open("result.txt","w")
    text = infile.read()
    position = text.find(key)
    if position == -1:
        outfile.write(key + " is not found.\n")
    else:
        outfile.write(key + " is at " + str(position) + ".\n")
    outfile.close()
    infile.close()
    print("Done")
    

    위 함수는 첫 번째 문자열만 찾는 함수입니다. 혹시 여기서 while 함수를 사용해서 마지막 문자열만 찾는 함수는 어떻게 만들 수 있을까요 ㅠ