A question about list

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pretoriano_2001@hotmail.com

    #1

    A question about list

    Hello:
    Variable 'a' has the next values:
    [[1,1],[2,2]]
    and I want to take a to b as:
    [[1,1,'='],[2,2,'=']]
    How can I do this with only one line of instruction?
    Thanks!!

  • Gerard Flanagan

    #2
    Re: A question about list


    pretoriano_2001 @hotmail.com wrote:
    Hello:
    Variable 'a' has the next values:
    [[1,1],[2,2]]
    and I want to take a to b as:
    [[1,1,'='],[2,2,'=']]
    How can I do this with only one line of instruction?
    Thanks!!
    >>a = [[1,1], [2,2]]
    >>map( lambda x: x + ['='], a )
    [[1, 1, '='], [2, 2, '=']]
    >>>

    Comment

    • Larry Bates

      #3
      Re: A question about list

      pretoriano_2001 @hotmail.com wrote:
      Hello:
      Variable 'a' has the next values:
      [[1,1],[2,2]]
      and I want to take a to b as:
      [[1,1,'='],[2,2,'=']]
      How can I do this with only one line of instruction?
      Thanks!!
      >
      To copy a list use:

      b=a[:]

      -Larry

      Comment

      • Bruno Desthuilliers

        #4
        Re: A question about list

        pretoriano_2001 @hotmail.com wrote:
        Hello:
        Variable 'a' has the next values:
        [[1,1],[2,2]]
        and I want to take a to b as:
        [[1,1,'='],[2,2,'=']]
        How can I do this with only one line of instruction?
        b = [item + ['='] for item in a]

        --
        bruno desthuilliers
        python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
        p in 'onurb@xiludom. gro'.split('@')])"

        Comment

        • rzed

          #5
          Re: A question about list

          pretoriano_2001 @hotmail.com wrote in news:1161102973 .920895.141500
          @i42g2000cwa.go oglegroups.com:
          Hello:
          Variable 'a' has the next values:
          [[1,1],[2,2]]
          and I want to take a to b as:
          [[1,1,'='],[2,2,'=']]
          How can I do this with only one line of instruction?
          Thanks!!
          >
          b = [[x,y,'='] for (x,y) in a]

          --
          rzed

          Comment

          • Larry Bates

            #6
            Re: A question about list

            Larry Bates wrote:
            pretoriano_2001 @hotmail.com wrote:
            >Hello:
            >Variable 'a' has the next values:
            >[[1,1],[2,2]]
            >and I want to take a to b as:
            >[[1,1,'='],[2,2,'=']]
            >How can I do this with only one line of instruction?
            >Thanks!!
            >>
            To copy a list use:
            >
            b=a[:]
            >
            -Larry
            Seems I may have misunderstood the question, but others
            have answered appropriately.

            -Larry

            Comment

            Working...