Python 不被忽略的重复项
我有以下代码:Python 不被忽略的重复项,python,Python,我有以下代码: def pStockName(): global StockList selfP = [] StockList = str(raw_input('Enter pipe separated list of StockS : ')).upper().strip() items = StockList.split("|") count = len(items) print 'Total Distinct Stock
def pStockName():
global StockList
selfP = []
StockList = str(raw_input('Enter pipe separated list of StockS : ')).upper().strip()
items = StockList.split("|")
count = len(items)
print 'Total Distinct Stock Count : ', count
items = list(set(StockList.split("|")))
pipelst = [i.replace('-mc','').replace('-MC','').replace('$','').replace('^','') for i in items]
filepath = '/location/Stock_Data.txt'
f = open(filepath, 'r')
for lns in f:
split_pipe = lns.split(':', 1)
if split_pipe[0] in pipelst:
pipelst.remove(split_pipe[0])
for lns in pipelst:
print bcolors.red + lns,' is wrong Stock Name' + bcolors.ENDC
f.close()
当我执行上述代码时,它要求我提供一些输入,如下所示:
输入单独的库存清单:aaa | aaa | hma
总存量:3
属于其他中心的股票:
来自其他中心的库存计数=0
属于当前中心的股票:
美国的活跃股票1:
^AAA$^AAA$^HMA$
忽略当前中心的库存计数=0
您已将属于此中心的库存列表输入为:
^AAA$^AAA$^HMA$
有效库存量:3
您是否希望继续持有这些股票[是| Y |否| N]:Y
当我输入(aaa | aaa | hma)并按enter键时,您可以看到上面的内容,并获取重复条目“aaa”。当我输入并按enter键时,我想忽略此重复条目。我想让您知道此输入可以是(aaa | aaa)或(aaa | aaa)或(aaa | aaa)。任何我想忽略的重复条目,无论大小写
请让我知道我在这里做错了什么。我如何修复此问题。尝试使用:
您从未编写任何代码来删除重复项。创建列表“项”时,请按照此答案中的建议(使用集合)删除重复项。请了解如何调试
集合
已在代码中。显然,代码与发布的代码不一致output@Garlywhale感谢它为我的工作与完整列表变量。但这很奇怪,我已经设置了代码。但它并没有以这种方式发挥作用。不管怎样,多谢你了。
selfP = []
StockList = str(raw_input('Enter pipe separated list of StockS : ')).upper().strip()
fullList = StockList.split("|")
items = list(set(fullList))
count = len(items)