Help with removing sequences from list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gsr1972
    New Member
    • Jul 2009
    • 3

    Help with removing sequences from list

    hi all,
    I am trying to remove the following from mylist
    mylist=[28, 227, 28, 227, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 68, 187, 68, 187, 7, 248, 7, 248, 0, 0, 0, 0, 0, 0, 0, 0, 70, 185, 70, 185, 2, 253, 2, 253]

    I only want to remove the zeros that are being repeated every 8th,24th item(in bold). I tried a few methods like using filter and all it worked but it also removed the zeros which i intend to keep like the 4th and 6th item in mylist...Is there a good way to do this?...thks
  • hidrkannan
    New Member
    • Feb 2007
    • 32

    #2
    Code:
    mylist=[28, 227, 28, 227, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 68, 187, 68, 187, 7, 248, 7, 248, 0, 0, 0, 0, 0, 0, 0, 0, 70, 185, 70, 185, 2, 253, 2, 253]
    removeIndexList = []
    for i in xrange(len(mylist)-1):
    	if mylist[i] == 0 and mylist[i+1] == 0:
    		removeIndexList.append(i)
    		removeIndexList.append(i+1)
    myfinallist = [eachElement for i, eachElement in enumerate(mylist) if i not in removeIndexList]

    Comment

    • gsr1972
      New Member
      • Jul 2009
      • 3

      #3
      Help with removing sequences from list

      tried it and it works...cool
      guess have lots to learn!
      thks!

      Comment

      Working...