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
2 1430 -
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]
-
-
-
-
tried it and it works...cool
guess have lots to learn!
thks!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: kartik |
last post by:
Escape sequences don't seem to work in strings within list comprehensions:
>>> print ]
What am I missing?
Thank you.
|
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...
|
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,...
|
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.
--
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |