편집 기록

편집 기록
  • 프로필 박정우님의 편집
    날짜2022.12.02

    영어단어 추출관련 코드 수정 문의


    안녕하세요, 파이썬을 공부하고있는 초보직장인입니다. 독학중에 막막한게 있어 답을 알아가고자 질문드립니다.

    word쪽에서 스플릿 이후 범위를 수정하면 에러가 뜨고 어떻게 해야할까요?

    def filter_by_text(text) :
        corpus = []
        with open('corpus.txt') as file:
            for tuple in file:
                word = tuple.strip().split('/')[0]
                freq = int(tuple.split('/')[1])
                if word[0] == text:
                    new_corpus=(word,freq)
                    corpus.append(new_corpus)
    
        print(sorted(corpus, key=lambda x:x[1], reverse=True)[:20])
    
    t = input()
    filter_by_text(t)
    
  • 프로필 nowp님의 편집
    날짜2022.12.02

    영어단어 추출관련 코드 수정 문의


    안녕하세요, 파이썬을 공부하고있는 초보직장인입니다. 독학중에 막막한게 있어 답을 알아가고자 질문드립니다.

    영어단어,빈도수 data를 corpus.txt로부터 추출하여, 단어의 첫번째 알파벳 실행시 해당 알파벳으로 시작하는 단어를 빈도수가 높은 것 부터 나열해주는 code입니다.

    print -> [('and' , 19899), ('at" . 14000) -------)]
    

    코드를 돌렸을때 문제는 없는데, 알파벳을 a / b 이런식으로 input 할땐 결과값이 나오지면

    두글자 즉 an, ex로 검색했을때도 위의 규칙대로 나오게끔하고싶은데 두글자를 넘어갈땐 결과값이 나오지 않습니다.

    word쪽에서 스플릿 이후 범위를 수정하면 에러가 뜨고 어떻게 해야할까요?

    def filter_by_text(text) :
        corpus = []
        with open('corpus.txt') as file:
            for tuple in file:
                word = tuple.strip().split('/')[0]
                freq = int(tuple.split('/')[1])
                if word[0] == text:
                    new_corpus=(word,freq)
                    corpus.append(new_corpus)
    
        result = []
        for tuple in corpus:
            wording = tuple[0]
            if wording.startswith(text):
                result.append(text)
    
        print(sorted(corpus, key=lambda x:x[1], reverse=True)[:20])
    
    t = input()
    filter_by_text(t)
    
  • 프로필 박정우님의 편집
    날짜2022.12.02

    영어단어 추출관련 코드 수정 문의


    안녕하세요, 파이썬을 공부하고있는 초보직장인입니다. 독학중에 막막한게 있어 답을 알아가고자 질문드립니다.

    영어단어,빈도수 data를 corpus.txt로부터 추출하여, 단어의 첫번째 알파벳 실행시 해당 알파벳으로 시작하는 단어를 빈도수가 높은 것 부터 나열해주는 code입니다.

    print -> [('and' , 19899), ('at" . 14000) -------)]

    ** 코드를 돌렸을때 문제는 없는데, 알파벳을 a / b 이런식으로 input 할땐 결과값이 나오지면

    두글자 즉 an, ex로 검색했을때도 위의 규칙대로 나오게끔하고싶은데 두글자를 넘어갈땐 결과값이 나오지 않습니다..

    word쪽에서 스플릿 이후 범위를 수정하면 에러가 뜨고 어떻게 해야할까요? ㅜㅜ**

    def filter_by_text(text) :
        corpus = []
        with open('corpus.txt') as file:
            for tuple in file:
                word = tuple.strip().split('/')[0]
                freq = int(tuple.split('/')[1])
                if word[0] == text:
                    new_corpus=(word,freq)
                    corpus.append(new_corpus)
    
        result = []
        for tuple in corpus:
            wording = tuple[0]
            if wording.startswith(text):
                result.append(text)
    
        print(sorted(corpus, key=lambda x:x[1], reverse=True)[:20])
    
    t = input()
    filter_by_text(t)