1

私はサイトとウェブをよく見ましたが、かなり具体的であるため、これを行う方法を見つけることができず、すべてを試しました!

検索を実行する機能があり、リスト内の特定の位置にあるプレーンテキストと文字列を出力しようとしています。

これは私のコードです:

def search_authors( the_author, authors ):

    position = 0

    foundAuthor = False

    for i in authors:
        if the_author in i:
                print((the_author)  + ". (" + str(years[position]) + "). " + str(titles[position]) + ". " + str(journals[position]) + ". "  )
                foundAuthor == True

        #
        #       for some reason this is prnting a dot on the next line, not just after the last entry
        #

        elif position == len(authors) and foundAuthor == False:
                print("not here")
        position += 1

これは、印刷時の出力です。

Anonymous. (1993). Technical correspondance - Random Number Generators. Communications       of the ACM
. 
Anonymous. (1992). Research Directions in Virtual Environments (NSF Invitational Workshop). Computer Graphics
. 
Anonymous. (1998). "Exploring sequential data: Commentary on Bowers, Jentsch, Salas, and Braun (1998)". Human Factors
. 

次の行に進む各検索結果の最後の完全な停止を停止する方法がわかりません。どんな助けでも大歓迎です。

4

1 に答える 1

1

ジャーナル リストの各要素には改行がある可能性があります。置き換えてみてください:

str(journals[position]).rstrip()

為に

str(journals[position])
于 2013-04-27T21:27:55.513 に答える