473,394 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
Jul 3 '09 #1
2 1430
Expand|Select|Wrap|Line Numbers
  1. 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]
  2. removeIndexList = []
  3. for i in xrange(len(mylist)-1):
  4.     if mylist[i] == 0 and mylist[i+1] == 0:
  5.         removeIndexList.append(i)
  6.         removeIndexList.append(i+1)
  7. myfinallist = [eachElement for i, eachElement in enumerate(mylist) if i not in removeIndexList]
  8.  
  9.  
  10.  
  11.  
Jul 3 '09 #2
tried it and it works...cool
guess have lots to learn!
thks!
Jul 3 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: kartik | last post by:
Escape sequences don't seem to work in strings within list comprehensions: >>> print ] What am I missing? Thank you.
4
by: temp | last post by:
Hi All, I wonder could someone help me with this? What I want to do is search through a list of letters and look for adjacent groups of letters that form sequences, not in the usual way of...
30
by: Steven Bethard | last post by:
George Sakkis wrote: > "Steven Bethard" <steven.bethard@gmail.com> wrote: >> Dict comprehensions were recently rejected: >> http://www.python.org/peps/pep-0274.html >> The reason, of course,...
4
by: Hemant Shah | last post by:
Folks, I have created bunch of sequences in DB2 7.2. How do I list all the defined sequences and if possible their current values? Thanks. --
72
by: Gregory Petrosyan | last post by:
Please visit http://www.python.org/peps/pep-0204.html first. As you can see, PEP 204 was rejected, mostly because of not-so-obvious syntax. But IMO the idea behind this pep is very nice. So,...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
7
by: Miguel E. | last post by:
Hi, I've been (self) studying Python for the past two months and I have had no background in OOP whatsoever. I was able to write an interactive program that randomly selects an item from a...
3
by: blubzouf | last post by:
I am searching some info about accessing files with stdio functions. I am able to open a file, read in it with freaf, write in it with fwrite, modifying its data in "r+" mode ( without truncation...
5
by: nuffnough | last post by:
This is python 2.4.3 on WinXP under PythonWin. I have a config file with many blank lines and many other lines that I don't need. read the file in, splitlines to make a list, then run a loop...
4
by: JJ | last post by:
Is there a way of checking that a line with escape sequences in it, has no strings in it (apart from the escape sequences)? i.e. a line with \n\t\t\t\t\t\t\t\r\n would have no string in it a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.