how to clear up a List in python?

Discussion in 'Python' started by python, May 25, 2006.

  1. python

    python Guest

    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?
     
    python, May 25, 2006
    #1
    1. Advertising

  2. python

    vbgunz Guest

    > 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!
     
    vbgunz, May 25, 2006
    #2
    1. Advertising

  3. python

    robert Guest

    python wrote:

    > 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
     
    robert, May 25, 2006
    #3
  4. python

    vbgunz Guest

    > 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!
     
    vbgunz, May 25, 2006
    #4
  5. python

    Damjan Guest

    >> 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.

    --
    damjan
     
    Damjan, May 25, 2006
    #5
  6. python

    vbgunz Guest

    > 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 :)
     
    vbgunz, May 25, 2006
    #6
  7. vbgunz wrote:

    >> 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>
     
    Fredrik Lundh, May 25, 2006
    #7
  8. python

    D H Guest

    Go "help" the perl list instead Fredrik Lundh

    Fredrik Lundh wrote:
    > vbgunz wrote:
    >
    >>> 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.
     
    D H, May 25, 2006
    #8
  9. Re: Go "help" the perl list instead Fredrik Lundh

    D H <> wrote in news::

    > 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

    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)
     
    A. Sinan Unur, May 25, 2006
    #9
  10. python

    vbgunz Guest

    > 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!
     
    vbgunz, May 25, 2006
    #10
  11. python

    Mirco Wahab Guest

    Re: Go "help" the perl list instead Fredrik Lundh

    Thus spoke D H (on 2006-05-25 23:12):
    > Fredrik Lundh wrote:
    >> if you don't know how to do things, you don't need to post.

    >
    > 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
     
    Mirco Wahab, May 25, 2006
    #11
  12. vbgunz wrote:

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

    >
    > 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>
     
    Fredrik Lundh, May 26, 2006
    #12
  13. python

    vbgunz Guest

    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.
     
    vbgunz, May 26, 2006
    #13
  14. vbgunz wrote:

    > 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
     
    George Sakkis, May 26, 2006
    #14
  15. python

    vbgunz Guest

    > 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.
     
    vbgunz, May 26, 2006
    #15
  16. George Sakkis wrote:

    > 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>
     
    Fredrik Lundh, May 26, 2006
    #16
  17. python

    vbgunz Guest

    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...
     
    vbgunz, May 26, 2006
    #17
  18. python

    Georg Brandl Guest

    vbgunz wrote:
    > 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
     
    Georg Brandl, May 26, 2006
    #18
  19. python

    Georg Brandl Guest

    vbgunz wrote:
    > 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
     
    Georg Brandl, May 26, 2006
    #19
  20. python

    vbgunz Guest

    > 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!
     
    vbgunz, May 26, 2006
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGF2aWQ=?=

    Clear Browser History List

    =?Utf-8?B?RGF2aWQ=?=, Feb 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    6,170
    Chris Jackson
    Feb 19, 2004
  2. VB Programmer

    How to clear Existing Project list?

    VB Programmer, Apr 7, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    404
    VB Programmer
    Apr 7, 2004
  3. Michael Jasn
    Replies:
    1
    Views:
    589
    John Harrison
    Nov 1, 2004
  4. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    1,093
    Mark Fitzpatrick
    Jan 31, 2008
  5. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    1,039
    Steven Cheng[MSFT]
    Mar 6, 2007
Loading...

Share This Page