python获取字符串行数_从字符串中计算行数

我需要创建一个程序,删除标点,一些特定的单词,重复和返回单词左边和他们各自的行。我还需要跟踪复制品。例如

Python空闲

索引器:键入行,以a结尾。仅在行首

吹来的是一阵轻快的风

从北方,我青春的北方。

风也很冷,比风还冷

昨天的风。

.

指数为:

轻快1

吹1

1、3、4级风

北2

青年2

冷3

昨天4

问题是:我需要跟踪剩余单词的行号以及它们的重复项。我不能那样做。在from string import *

stopWords = [ "a", "i", "it", "am", "at", "on", "in", "to", "too", "very", \

"of", "from", "here", "even", "the", "but", "and", "is", "my", \

"them", "then", "this", "that", "than", "though", "so", "are" ]

endings = [ "es" , "ed" , "er", "ly"]

punctuation = [ ".", "," , ":" , ";" , "!" , "?" , "&" , "'" ]

unindexed_sentence = raw_input("type in lines, finish with a . at start of line only").lower()

#removing duplicates.

def unique_string(l):

ulist = []

ulist2 = []

[ulist.append(x) for x in l if x not in ulist]

[ulist2.append(x)]

global ulist2

return ulist

unindexed_sentence =' '.join(unique_string(unindexed_sentence.split()))

unindexed_sentence1 = split(unindexed_sentence,"\n")

list_unindexed = []

# splitting

i = 0

while i

list_unindexed += [split(unindexed_sentence1[i])]

i+=1

countline = 0

i = 0

while i < len(list_unindexed):

j = 0

while j < len(list_unindexed[i]):

if list_unindexed[i][j][0] in punctuation:

list_unindexed[i][j] = list_unindexed[i][j][:0]

if list_unindexed[i][j][-1] in punctuation:

list_unindexed[i][j] = list_unindexed[i][j][:-1]

if list_unindexed[i][j][-1] == "s":

list_unindexed[i][j] = list_unindexed[i][j][:-1]

if list_unindexed[i][j][-2:] in endings:

list_unindexed[i][j] = list_unindexed[i][j][:-2]

if list_unindexed[i][j][-3:] == "ing":

list_unindexed[i][j] = list_unindexed[i][j][:-3]

if list_unindexed[i][j] in stopWords:

del list_unindexed[i][j]

else:

j += 1

i += 1

countline += 1

def new_line(n):

split(n,"\n")

count = 1

if n[-1] == "\n":

count += 1

return count

string1 = str(list_unindexed)

string2 = str(string1)

string2 ='\n'.join(unique_string(string2.split()))

print string2

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值