471,339 Members | 1,250 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Delete values from a string using the index

How do I delete or remove values from a list or string using the
index.

If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would I do
that?

Thanks.

Sep 26 '07 #1
6 4680
ko****@hotmail.com wrote:
How do I delete or remove values from a list or string using the
index.

If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would
I do that?
del a[0:5]

Be sure to check out the relevant section of the Python tutorial.

http://docs.python.org/tut/node7.html

Regards,
Björn

--
BOFH excuse #31:

cellular telephone interference

Sep 26 '07 #2
ko****@hotmail.com wrote:
How do I delete or remove values from a list or string using the
index.

If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would I do
that?

Thanks.
del a[1]
del a[-5]

Sep 26 '07 #3
On Sep 26, 2007, at 3:25 PM, ko****@hotmail.com wrote:
How do I delete or remove values from a list or string using the
index.

If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would I do
that?

Thanks.

--
http://mail.python.org/mailman/listinfo/python-list
>>l = [1, 2, 3]
del l[1]
l
[1, 3]

Erik Jones

Software Developer | Emma®
er**@myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com
Sep 26 '07 #4
ko****@hotmail.com wrote:
How do I delete or remove values from a list or string using the
index.

If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would I do
that?

Thanks.
If you want to do it all at once :

del a[1:4:2]
Sep 26 '07 #5
ko****@hotmail.com a écrit :
How do I delete or remove values from a list
del
or string
You can't. Python's strings are immutables.
using the
index.

If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would I do
that?
del a[0:5]
print a

Sep 27 '07 #6
In message <11*********************@y42g2000hsy.googlegroups. com>,
ko****@hotmail.com wrote:
How do I delete or remove values from a list or string using the
index.
Note you can't do it with a string, since that's not mutable.
Sep 27 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Philip Boonzaaier | last post: by
reply views Thread by David C | last post: by
7 posts views Thread by ITAutobot25 | last post: by
2 posts views Thread by William LaMartin | last post: by
8 posts views Thread by Michel Esber | last post: by
reply views Thread by rosydwin | last post: by

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.