-1

I have below code :

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()

when I execute above code it asks me to give some input as below :

Enter pipe separated list of StockS : aaa|aaa|hma

Total Distinct Stock Count : 3

Stocks Belonging to other Centers :

Stock Count From Other Center = 0

Stocks Belonging to Current Centers :

Active Stocks in US1 :

^AAA$|^AAA$|^HMA$

Ignored Stock Count From Current Center = 0

You Have Entered StockList belonging to this Center as: ^AAA$|^AAA$|^HMA$

Active Stock Count : 3

Do you wish to continue with these StockS [YES|Y|NO|N] : Y

You are seeing above when I give input (aaa|aaa|hma) and press enter its taking the duplicate entry "aaa" . I want to ignore this duplicate entry when I give the input and press enter. I would like to let you know this input can be as (aaa|AAA) or (AAA|AAA) or (aaa|aaa). Any how any duplicate entry I want to ignore irrespective of upper or lower case.

Please let me know what wrong I did here any how can I fix this.

Ritesh
  • 51
  • 6
  • You never wrote any code to remove duplicates. One you create the list 'items' follow the advice in this answer (using sets) to remove duplicates. http://stackoverflow.com/questions/7961363/python-removing-duplicates-in-lists – SBH Jul 28 '15 at 19:00
  • please learn how to debug – akonsu Jul 28 '15 at 19:04

1 Answers1

1

Try using set: ...

selfP = []
    StockList = str(raw_input('Enter pipe separated list of StockS : ')).upper().strip()
fullList = StockList.split("|")
items = list(set(fullList))
count = len(items)
Gnarlywhale
  • 4,030
  • 2
  • 15
  • 18
  • the `set` is already in the code. apparently the code does not correspond to the posted output – akonsu Jul 28 '15 at 19:04
  • @Garlywhale Thanks It worked for me with fullList variable. But that's strange, I have already set in code. But it was not worked by that way. Any ways thanks a lot Gnarlywhale. – Ritesh Jul 28 '15 at 19:20