Remove duplicates from list

Derek Perriero derek.perriero at gmail.com
Thu Jun 9 20:44:21 CEST 2005


I've been un-triumphantly trying to get a list of mine to have no repeats in 
it. First, I'm pulling attributes from Zope and forming a list. Next, I'm 
pulling those same values and comparing them against the same list and if 
the values equal each other and are not already in the list, they append to 
my 'nodupes' list. My current result is showing what I put in I am getting 
out. Below the code is my output of 'nodupes' list. Here's the snippet. 

regHours = context.getMainPrint(); <---attributes from Zope

libslist = []
nodupes = []

#collect libraries
for libs in regHours:
cache = libs.Monday + libs.Tuesday + libs.Wednesday + libs.Thursday + 
libs.Friday + libs.Saturday + libs.Sunday
libslist.append(cache)

#pull repeated values
for item in regHours:
collect = item.Monday + item.Tuesday + item.Wednesday + item.Thursday + 
item.Friday + item.Saturday + item.Sunday
libName = item.libraryName

for libs in libslist: 
if collect == libs and libs not in nodupes:
nodupes.append(libs)

*My Current Output:*
['8am - 9pm8am - 9pm8am - 9pm8am - 9pm8am - 5pm9am - 5pm6pm - 10pm', '8am - 
9pm8am - 9pm8am - 9pmClosed8am - 5pm9am - 5pm6pm - 10pm', '8am - 9pm8am - 
9pm8am - 9pm8am - 9pm8am - 5pm9am - 5pmClosed', '9am - 8pm9am - 8pm9am - 
8pm9am - 8pm9am - 8pm9am - 6pm12pm - 6pm', '9am - 5pm9am - 5pm9am - 5pm9am - 
5pm9am - 5pmClosedClosed', '10am - 5pm10am - 5pm10am - 5pm10am - 5pm10am - 
5pm10am - 5pmClosed']

Thanks





-- 
Perriero, Derek
derek.perriero at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050609/bfacc01f/attachment.html>


More information about the Python-list mailing list