how to clear up a List in python?

P

python

I have new a list , when it hava large number of values, I wonna to
delete all the values in it,how to do?
And, if a list have 801 values, I want to get its values index from 300
to 400, could use list1[300:400],are right me?
 
V

vbgunz

I have new a list , when it hava large number of values, I wonna to
delete all the values in it,how to do?

something like this will probably help.

x = [1,2,3,4,5,6,7,8,9]
y = x

list([x.pop() for z in xrange(len(x))])

print x, y # [] []
And, if a list have 801 values, I want to get its values index from 300
to 400, could use list1[300:400],are right me?

300 will be included in your slice whereas the 400th index will be
excluded. you will ultimately have 99 items in your slice. if you want
values from index 300 to 400 you'll need to say [300:401]. the first
index is included. the last index is excluded.

good luck!
 
R

robert

python said:
I have new a list , when it hava large number of values, I wonna to
delete all the values in it,how to do?
And, if a list have 801 values, I want to get its values index from 300
to 400, could use list1[300:400],are right me?


del list1[:]
del list1[:-1000] # keep max. last 1000 appended items in the list
list1[:]=replace_list
....

-robert
 
V

vbgunz

del list1[:]

thank you for that reply. I never thought of [:] cause to be me I
thought it would immediately make a copy of the list or if anything
that it would delete a copy so I never played with it. nice :)
del list1[:-1000] # keep max. last 1000 appended items in the list
list1[:]=replace_list

very much thanks for the tips. they're great!
 
D

Damjan

And, if a list have 801 values, I want to get its values index from 300
to 400, could use list1[300:400],are right me?

300 will be included in your slice whereas the 400th index will be
excluded. you will ultimately have 99 items in your slice.

No, he'll have 100 items in the slice... 300, 301,... 399 that's 100 items.
 
V

vbgunz

No, he'll have 100 items in the slice... 300, 301,... 399 that's 100 items.

you're right, sorry. [300:400] would return 100 items but the item at
index 400 would not return. I suggested if he wanted it to try
[300:401] as the last slice index is excluded from the return.

Thanks for that :)
 
F

Fredrik Lundh

vbgunz said:
I have new a list , when it hava large number of values, I wonna to
delete all the values in it,how to do?

something like this will probably help.

x = [1,2,3,4,5,6,7,8,9]
y = x

list([x.pop() for z in xrange(len(x))])

print x, y # [] []

if you don't know how to do things, you don't need to post.

if you know why this is about the dumbest way to do what you're doing,
and you're posted this on purpose, you really need to grow up.

</F>
 
D

D H

Fredrik said:
vbgunz said:
I have new a list , when it hava large number of values, I wonna to
delete all the values in it,how to do?

something like this will probably help.

x = [1,2,3,4,5,6,7,8,9]
y = x

list([x.pop() for z in xrange(len(x))])

print x, y # [] []

if you don't know how to do things, you don't need to post.

if you know why this is about the dumbest way to do what you're doing,
and you're posted this on purpose, you really need to grow up.

</F>

He already posted before your post that he made a mistake.
You obviously ignored that and invented some argument that he
posted with malicious intentions. That better describes most of
your thousands of annoying posts.
 
A

A. Sinan Unur

D H said:
You obviously ignored that and invented some argument that he
posted with malicious intentions. That better describes most of
your thousands of annoying posts.

I don't know what describes what you did. What is the point of bringing
clpmisc into this argument.

Anyway, *PLONK*

Sinan
 
V

vbgunz

if you don't know how to do things, you don't need to post.
if you know why this is about the dumbest way to do what you're doing,
and you're posted this on purpose, you really need to grow up.

If this was the case who then would post any questions? I not only made
my post with the best of intentions but felt attaching a strongly
worded and lengthy warranty over the script performance and pythonic
value would be overkill. I admit I am not the best at Python and I have
no problem in being offered a more optimized solution but to insult me
is childish. no?

It's ok and I have no grudge with you Fredrik. I would appreciate
though you simply point out my error with a suggested solution and if
energy permit, tell me why my solution is not so good and why yours is
better. I would value that very much. Also, not to be the dummy or
anything but my solution did exactly what the first poster requested.

Robert happened to point out a much better and most likely preffered
alternative solution. It was great! I live and I learn.

Have a good day!
 
M

Mirco Wahab

Thus spoke D H (on 2006-05-25 23:12):
He already posted ...

Based on your Text, you can (in Perl, of course ;-)
extract the Goedel-Number sequence (prime number
sequence) of it:

use Acme::Goedelize;

my $goed = new Acme::Goedelize;
my $rant = do { local $/; (<DATA>) };
$rant = ~s/[.\n]//mg;
print join "\n", $goed->to_number($rant)=~/(\d{64})/g;

__DATA__
He already posted before your post that he made a mistake.
You obviously ignored that and invented some argument that he
posted with malicious intentions. That better describes most of
your thousands of annoying posts.


This prints a (64 char blocked) "Version"
of your text, which can be retranslated
to your text by 'degoedelization'.

How'd you do *that* in Python ;-)

Regards

Mirco

f'up c.l.python
 
F

Fredrik Lundh

vbgunz said:
If this was the case who then would post any questions?

you didn't post a question, you provided a ludicrously bad solution in
response to a simple question.

that's not a good way to promote Python.

</F>
 
V

vbgunz

I will not try and stop helping others because you don't like my
answers. I found a perfectly good way how not to do something that
wasn't exactly wrong anyway. if you can take another persons honest
attempt to help someone and twist it into something it is not, I can
only suggest you look in the mirror and only if you're truly perfect
you continue your banter.

by the way, I am not here to promote Python. but if this is of your
concern, perhaps maybe you should rethink how you respond in kind
towards post you do not exactly agree with. Others are reading this and
it might not come off as promotional material. Also, if you're having a
bad day, take a rest and relax. You just might deserve it.
 
G

George Sakkis

vbgunz said:
I will not try and stop helping others because you don't like my
answers. I found a perfectly good way how not to do something that
wasn't exactly wrong anyway. if you can take another persons honest
attempt to help someone and twist it into something it is not, I can
only suggest you look in the mirror and only if you're truly perfect
you continue your banter.

by the way, I am not here to promote Python. but if this is of your
concern, perhaps maybe you should rethink how you respond in kind
towards post you do not exactly agree with. Others are reading this and
it might not come off as promotional material. Also, if you're having a
bad day, take a rest and relax. You just might deserve it.

I guess Fredrik's message was more along the lines of ``don't try to
"help" others after a week or two toying with the language because you
might be offering disservice, despite your good intentions; leave this
to more experienced users``. The words might have been a bit harsher
but that's just his style; you'll get used to it if you hang around
here often.

George
 
V

vbgunz

I guess Fredrik's message was more along the lines of ``don't try to
"help" others after a week or two toying with the language because you
might be offering disservice, despite your good intentions; leave this
to more experienced users``. The words might have been a bit harsher
but that's just his style; you'll get used to it if you hang around
here often.

I much rather stand corrected than to silently remain ignorant. I take
revision of my solution for all it's worth but to be belittled without
correction is arrogant and unnecessary. I've been working with Python
for several months now and I feel I know plenty *but* I am still
learning.

I personally never had to clear a list. I never thought of Roberts
answer and my reasoning is in Roberts message. In the end I stood
correct because Robert was nice enough to answer two birds with one
stone. Fredrik on the other hand had nothing positive to add and his
message seemed gestapo.

Where I come from and how I grew up is quite simple. A wrong answer is
better than no answer and a worthless remark is worth garbage. Why?
Because no right answer is gospel and no answer no matter how dumb is
cause for discourtesy. I tried and thats the bottom line.
 
F

Fredrik Lundh

George said:
I guess Fredrik's message was more along the lines of ``don't try to
"help" others after a week or two toying with the language because you
might be offering disservice, despite your good intentions; leave this
to more experienced users``.

no matter what Doug Holton and "vbgunz" thinks, if you ask a question on
comp.lang.python and use the answer you're getting, you shouldn't end up
on thedailywtf.com.

</F>
 
V

vbgunz

Fredrik_Lundh = 'wah'

I bet you enjoy stealing candy from babies and dunging on the little
guy every chance you get. You're suppose to be a role model in this
community? Your temper tantrum and unrelenting 'look at me look at me
i'm bigger and better' machismo attitude is nothing more than a decoyed
ploy set out by a deluded megalomaniac. You're promoting Python or the
fact that you're the son of Zeus and Hera? You're the worse sore losing
cry baby I've ever witnessed on the net in my ten years here...
pathetic for sure...
 
G

Georg Brandl

vbgunz said:
Fredrik_Lundh = 'wah'

I bet you enjoy stealing candy from babies and dunging on the little
guy every chance you get. You're suppose to be a role model in this
community? Your temper tantrum and unrelenting 'look at me look at me
i'm bigger and better' machismo attitude is nothing more than a decoyed
ploy set out by a deluded megalomaniac.

Personally speaking, Fredrik's just sitting here beneath me, and I can assure
you that he's not screaming "I'm bigger and better than you all" every
few minutes. He may be screaming "I made it faster!", but that's why we're
here ;)
> You're promoting Python or the
> fact that you're the son of Zeus and Hera? You're the worse sore losing
> cry baby I've ever witnessed on the net in my ten years here...
> pathetic for sure...

You perhaps shouldn't become so excited. Next time, if you're not sure of
the correctness of your solution, try to wait a bit before posting it,
and see if someone other comes up with the same thing you would have posted.

Georg
 
G

Georg Brandl

vbgunz said:
Fredrik_Lundh = 'wah'

I bet you enjoy stealing candy from babies and dunging on the little
guy every chance you get. You're suppose to be a role model in this
community? Your temper tantrum and unrelenting 'look at me look at me
i'm bigger and better' machismo attitude is nothing more than a decoyed
ploy set out by a deluded megalomaniac.

Personally speaking, Fredrik's just sitting here next to me, and I can assure
you that he's not screaming "I'm bigger and better than you all" every
few minutes. He may be screaming "I made it faster!", but that's why we're
here ;)
> You're promoting Python or the
> fact that you're the son of Zeus and Hera? You're the worse sore losing
> cry baby I've ever witnessed on the net in my ten years here...
> pathetic for sure...

You perhaps shouldn't become so excited. Next time, if you're not sure of
the correctness of your solution, try to wait a bit before posting it,
and see if someone other comes up with the same thing you would have posted.

Georg
 
V

vbgunz

You perhaps shouldn't become so excited. Next time, if you're not sure of
the correctness of your solution, try to wait a bit before posting it,
and see if someone other comes up with the same thing you would have posted.

George, if Frederik's first reply was replaced with yours chances are
this little waste of time would have never had taken place. I am not an
animal and I am capable of understanding my mistakes but trying to
embarass me and belittle me in front of all of my peers here when all I
tried to do was help is absolutely pathetic the first time around.

I don't try to come off as a know it all here and I don't feel I should
post a gospel warning label on my help signature but Fredrik could have
delivered his message in a much better tone. I too am learning Python
and if maybe my answer was not evident enough of that then how smart is
Fredrik to persecute me for it?

I don't wish to question Fredriks knowledge or his position in the
whole scheme of Python but to disrespect me in the name of arrogance
and call it just is a mislabel. I don't wish to carry on with this, I
don't... I just have no love for a bully and Fredrik is proving himself
to be just that.

Good day George!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top