list problem...

Discussion in 'Python' started by Rog, Sep 28, 2010.

  1. Rog

    Rog Guest

    Hi all,
    Have been grappling with a list problem for hours...
    a = [2, 3, 4, 5,.....]
    b = [4, 8, 2, 6,.....]
    Basicly I am trying to place a[0], b[0] in a seperate list
    IF a[2] and b[2] is present.
    I have tried sets, zip etc with no success.
    I am tackling Euler projects with Python 3.1, with minimal
    knowledge, and having to tackle the language as I progress.
    Enjoyable frustration :)

    --
    Rog
    http://www.rog.pynguins.com
     
    Rog, Sep 28, 2010
    #1
    1. Advertising

  2. On Tue, Sep 28, 2010 at 11:44 AM, Rog <> wrote:
    > Hi all,
    > Have been grappling with a list problem for hours...
    > a = [2, 3, 4, 5,.....]
    > b = [4, 8, 2, 6,.....]
    > Basicly I am trying to place a[0], b[0] in a seperate list
    > IF a[2] and b[2] is present.
    > I have tried sets, zip etc with no success.
    > I am tackling Euler projects with Python 3.1, with minimal
    > knowledge, and having to tackle the language as I progress.
    > Enjoyable frustration  :)


    I'm not clear on what your actual problem is, could you restate it?

    It sounds like you want to copy the ith element out of a and b into
    some other list- call it c- when the (i+2)th element meets some
    condition. What's the condition?

    Geremy Condra
     
    geremy condra, Sep 28, 2010
    #2
    1. Advertising

  3. Rog

    Rog Guest

    On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote:

    > On Tue, Sep 28, 2010 at 11:44 AM, Rog <> wrote:
    >> Hi all,
    >> Have been grappling with a list problem for hours... a = [2, 3, 4,
    >> 5,.....]
    >> b = [4, 8, 2, 6,.....]
    >> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and
    >> b[2] is present.
    >> I have tried sets, zip etc with no success. I am tackling Euler projects
    >> with Python 3.1, with minimal knowledge, and having to tackle the
    >> language as I progress. Enjoyable frustration  :)

    >
    > I'm not clear on what your actual problem is, could you restate it?
    >
    > It sounds like you want to copy the ith element out of a and b into some
    > other list- call it c- when the (i+2)th element meets some condition.
    > What's the condition?
    >
    > Geremy Condra


    The condition is that the i-th element is inverted, but not equal.
    eg 4,2 - 2,4 , 34,5 - 5,34 etc.
    Hope that is clearer.
    Thanks for the response.
    --
    Rog
    http://www.rog.pynguins.com
     
    Rog, Sep 28, 2010
    #3
  4. On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote:

    > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote:
    >
    >> On Tue, Sep 28, 2010 at 11:44 AM, Rog <> wrote:
    >>> Hi all,
    >>> Have been grappling with a list problem for hours... a = [2, 3, 4,
    >>> 5,.....]
    >>> b = [4, 8, 2, 6,.....]
    >>> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and
    >>> b[2] is present.
    >>> I have tried sets, zip etc with no success. I am tackling Euler
    >>> projects with Python 3.1, with minimal knowledge, and having to tackle
    >>> the language as I progress. Enjoyable frustration  :)

    >>
    >> I'm not clear on what your actual problem is, could you restate it?
    >>
    >> It sounds like you want to copy the ith element out of a and b into
    >> some other list- call it c- when the (i+2)th element meets some
    >> condition. What's the condition?
    >>
    >> Geremy Condra

    >
    > The condition is that the i-th element is inverted, but not equal. eg
    > 4,2 - 2,4 , 34,5 - 5,34 etc.
    > Hope that is clearer.


    Clear as mud.

    Perhaps you should given an example. Given input

    a = [2, 3, 4, 5, 6, 7]
    b = [4, 8, 2, 6, 10, 42]

    what output are you expecting, and how would you work it out by hand?





    --
    Steven
     
    Steven D'Aprano, Sep 29, 2010
    #4
  5. Rog

    Guest

    On 29 sep, 14:17, Steven D'Aprano <st...@REMOVE-THIS-
    cybersource.com.au> wrote:
    > On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote:
    > > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote:

    >
    > >> On Tue, Sep 28, 2010 at 11:44 AM, Rog <> wrote:
    > >>> Hi all,
    > >>> Have been grappling with a list problem for hours... a = [2, 3, 4,
    > >>> 5,.....]
    > >>> b = [4, 8, 2, 6,.....]
    > >>> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and
    > >>> b[2] is present.
    > >>> I have tried sets, zip etc with no success. I am tackling Euler
    > >>> projects with Python 3.1, with minimal knowledge, and having to tackle
    > >>> the language as I progress. Enjoyable frustration  :)

    >
    > >> I'm not clear on what your actual problem is, could you restate it?

    >
    > >> It sounds like you want to copy the ith element out of a and b into
    > >> some other list- call it c- when the (i+2)th element meets some
    > >> condition. What's the condition?

    >
    > >> Geremy Condra

    >
    > > The condition is that the i-th element is inverted, but not equal. eg
    > > 4,2 - 2,4 , 34,5 - 5,34 etc.
    > > Hope that is clearer.

    >
    > Clear as mud.
    >
    > Perhaps you should given an example. Given input
    >
    > a = [2, 3, 4, 5, 6, 7]
    > b = [4, 8, 2, 6, 10, 42]
    >
    > what output are you expecting,


    AFAICT, the OP expects [2, 4] in this case, but it's not clear what
    he'd expect for let's say:

    a = [2, 3, 21, 4, 5, 6, 7]
    b = [4, 8, 22, 2, 6, 10, 42]

    (the 'reversed' pair is at i+3, not i+2)

    or

    a = [0, 2, 3, 4, 5, 6, 7]
    b = [3, 4, 8, 2, 6, 10, 42]

    (the first pair is at pos 1, not 0)

    or

    a = [2, 3, 4, 8, 6, 7]
    b = [4, 8, 2, 3, 10, 42]

    (there's a second 'non-reversed/reversed' match at positions resp. 1 &
    3)
     
    , Sep 29, 2010
    #5
  6. Rog

    Rog Guest

    On Wed, 29 Sep 2010 05:52:32 -0700, wrote:

    > On 29 sep, 14:17, Steven D'Aprano <st...@REMOVE-THIS- cybersource.com.au>
    > wrote:
    >> On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote:
    >> > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote:

    >>
    >> >> On Tue, Sep 28, 2010 at 11:44 AM, Rog <> wrote:
    >> >>> Hi all,
    >> >>> Have been grappling with a list problem for hours... a = [2, 3, 4,
    >> >>> 5,.....]
    >> >>> b = [4, 8, 2, 6,.....]
    >> >>> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2]
    >> >>> and b[2] is present.
    >> >>> I have tried sets, zip etc with no success. I am tackling Euler
    >> >>> projects with Python 3.1, with minimal knowledge, and having to
    >> >>> tackle the language as I progress. Enjoyable frustration  :)

    >>
    >> >> I'm not clear on what your actual problem is, could you restate it?

    >>
    >> >> It sounds like you want to copy the ith element out of a and b into
    >> >> some other list- call it c- when the (i+2)th element meets some
    >> >> condition. What's the condition?

    >>
    >> >> Geremy Condra

    >>
    >> > The condition is that the i-th element is inverted, but not equal. eg
    >> > 4,2 - 2,4 , 34,5 - 5,34 etc.
    >> > Hope that is clearer.

    >>
    >> Clear as mud.
    >>
    >> Perhaps you should given an example. Given input
    >>
    >> a = [2, 3, 4, 5, 6, 7]
    >> b = [4, 8, 2, 6, 10, 42]
    >>
    >> what output are you expecting,

    >
    > AFAICT, the OP expects [2, 4] in this case, but it's not clear what he'd
    > expect for let's say:
    >
    > a = [2, 3, 21, 4, 5, 6, 7]
    > b = [4, 8, 22, 2, 6, 10, 42]
    >
    > (the 'reversed' pair is at i+3, not i+2)
    >
    > or
    >
    > a = [0, 2, 3, 4, 5, 6, 7]
    > b = [3, 4, 8, 2, 6, 10, 42]
    >
    > (the first pair is at pos 1, not 0)
    >
    > or
    >
    > a = [2, 3, 4, 8, 6, 7]
    > b = [4, 8, 2, 3, 10, 42]
    >
    > (there's a second 'non-reversed/reversed' match at positions resp. 1 & 3)



    It is true that I would have needed any 'non-reversed/reversed' pairs,
    these would have been the amicable pairs I was looking for.
    The method to recognise them eluded me. Eyes are not good enough :)
    I have now joined Python-List and will follow the correct route.
    I have used a method suggested that has made the problem redundant,
    though it will bug me from now on.

    g = []

    def divsum(n):
    return sum(i for i in range(1, n) if not n % i)

    for x in range(10000, 2, -1):
    c = divsum(x)
    v = divsum(c)
    if v == x and v != c:
    g.append(divsum(x))
    else:
    continue

    print(sum(g))

    --
    Rog
    http://www.rog.pynguins.com
     
    Rog, Sep 29, 2010
    #6
    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. roopa
    Replies:
    6
    Views:
    781
    Jerry Coffin
    Aug 27, 2004
  2. dackz
    Replies:
    0
    Views:
    502
    dackz
    Feb 6, 2007
  3. Debajit Adhikary
    Replies:
    17
    Views:
    707
    Debajit Adhikary
    Oct 18, 2007
  4. OW Ghim Siong
    Replies:
    2
    Views:
    417
    Peter Otten
    Nov 30, 2010
  5. asil klin
    Replies:
    28
    Views:
    1,323
    Andreas Leitgeb
    Mar 5, 2011
Loading...

Share This Page