Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97998

Re: i want to print next element i liste

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.python
Subject Re: i want to print next element i liste
Date Thu, 29 Oct 2015 12:48:35 +0000 (UTC)
Organization A noiseless patient Spider
Lines 36
Message-ID <n0t4j2$b2m$1@dont-email.me> (permalink)
References <25e0abea-f1a6-446c-af4e-f01fb5b482f0@googlegroups.com> <76077a86-40cf-42b0-bace-a8c25c03729e@googlegroups.com> <n0qs11$3v5$1@dont-email.me> <f4b6cec8-0404-46ee-bc60-49f721c5cb6e@googlegroups.com> <0cb60a10-186b-45fb-8170-28003e901921@googlegroups.com> <sPudnc0nj4EbHazLnZ2dnUU7-a2dnZ2d@giganews.com> <fea1d5fa-e3c8-40f4-9372-669634938718@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Thu, 29 Oct 2015 12:48:35 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="66ffcfa4470a58bcddbdcd1913f98ab4"; logging-data="11350"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GH0ULB9mXg2SgKAzs9+KP+WD/9VrUyvI="
User-Agent Pan/0.136 (I'm far too busy being delicious; GIT 926a150 git://git.gnome.org/pan2)
Cancel-Lock sha1:Ij4cqGkSWuGYBh6KUjtSppvkWo0=
Xref csiph.com comp.lang.python:97998

Show key headers only | View raw


On Thu, 29 Oct 2015 01:55:51 -0700, Ellelele Toget wrote:

> i put all packets in list and after i will find least 3 duplicate
> packets and it print soon coming next packet, if it is 3 duplicate
> packets it print 4. packet. if it is 25 duplicate packet it print 26.
> packet. Algorithm run so:)

So in a list of things, you want to find the thing that comes after the 
third occurrence of another thing.

Now I think we know what you actually want to do.

This probably isn't the best way to do it, but it seems to work:

#!/usr/bin/python

l = ["house", "book", "pen", "book", "pencil", "book", "clock", "cat", 
"book", "good", "write"]

d = {}

flag = False
for thing in l:
    if flag:
        print thing
        break
    else:
        if thing in d:
            d[thing] = d[thing] + 1
            if d[thing] == 3:
                flag = True
        else:
            d[thing] = 1

-- 
Denis McMahon, denismfmcmahon@gmail.com

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

i want to print next element i liste ellelelet@gmail.com - 2015-10-28 05:23 -0700
  Re: i want to print next element i liste darnold <darnold992000@yahoo.com> - 2015-10-28 07:05 -0700
    Re: i want to print next element i liste darnold <darnold992000@yahoo.com> - 2015-10-28 07:16 -0700
  Re: i want to print next element i liste Ellelele Toget <ellelelet@gmail.com> - 2015-10-28 07:34 -0700
    Re: i want to print next element i liste Christian Gollwitzer <auriocus@gmx.de> - 2015-10-28 17:12 +0100
      Re: i want to print next element i liste Ellelele Toget <ellelelet@gmail.com> - 2015-10-28 14:58 -0700
        Re: i want to print next element i liste Ellelele Toget <ellelelet@gmail.com> - 2015-10-28 15:02 -0700
          Re: i want to print next element i liste Larry Hudson <orgnut@yahoo.com> - 2015-10-28 19:12 -0700
            Re: i want to print next element i liste Ellelele Toget <ellelelet@gmail.com> - 2015-10-29 01:55 -0700
              Re: i want to print next element i liste Denis McMahon <denismfmcmahon@gmail.com> - 2015-10-29 12:48 +0000

csiph-web