我有一个文本文件,它由类似的行组成,很少有半个类似于文本文件中的其他行。
Input.txt
I would like to play: Volleyball
I would like to play: Volleyball
I would like to play: TableTennis
I would like to play: Baseball
I do not know how to play: Volleyball
She would like to play: TableTennis
I want to learn how to play: Baseball
They like to play: all the three
从输入文件中,我想删除重复的行,如图所示
I would like to play: Volleyball
I would like to play: TableTennis
I would like to play: Baseball
I do not know how to play: Volleyball
She would like to play: TableTennis
I want to learn how to play: Baseball
They like to play: all three
从输入文件中,我想删除重复的行,如图所示
I would like to play: Volleyball
I would like to play: TableTennis
I would like to play: Baseball
I do not know how to play: Volleyball
She would like to play: TableTennis
I want to learn how to play: Baseball
They like to play: all three
下一步:
I would like to play
They like to play
输出文件的简要说明我想玩的语句涵盖了许多不同的运动,所以我想打印出来。他们喜欢玩的最后一行是不同的情况,所以我也想打印那一行。(我们将这些结果写入.csv格式,并在不同的列中打印覆盖最大数量的运动以及所有独特运动的语句如何?)
注意:我不想打印我不知道怎么玩:排球她想玩:乒乓球我想学习如何玩:棒球
因为已经有三项运动
我对如何将同一文本文件中的一行与另一行进行比较感到困惑。
2条答案
按热度按时间x6h2sr281#
您可以按照以下步骤操作:
或
xu3bshqb2#
这很简单,在你的'.py'文件中这样做: