the first element in the list of list

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Bush

    the first element in the list of list

    I have a lis:
    [[1,3],[3,4],[5,6],[8,9],[14,0],[15,8]]
    I want a code to test when the difference between the first element in
    the list of list is equal to or larger than 6, then move the previous
    lists to the end of the list. that is:
    [[14,0],[15,8],[1,3],[3,4],[5,6],[8,9]]
  • bruno at modulix

    #2
    Re: the first element in the list of list

    Ben Bush wrote:[color=blue]
    > I have a lis:
    > [[1,3],[3,4],[5,6],[8,9],[14,0],[15,8]]
    > I want a code[/color]

    Then write it.

    And when (if) you have problems with it, repost, we'll then be happy to
    help you.
    [color=blue]
    > to test when the difference between the first element in
    > the list of list is equal to or larger than 6,[/color]

    I'm afraid you will never know what that difference is... Reminds me of
    zen koan saying "the difference between a bird is that it neither know
    how to fly".

    Note that the use of "between" usually implies a second term !-)

    BTW, also note that "the first element the first element in (a) list of
    list(s)" is usually (well, I'd even say "always") a list itself.
    [color=blue]
    > then move the previous
    > lists to the end of the list. that is:
    > [[14,0],[15,8],[1,3],[3,4],[5,6],[8,9]][/color]


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

    Comment

    • Dennis Benzinger

      #3
      Re: the first element in the list of list

      Ben Bush schrieb:[color=blue]
      > I have a lis:
      > [[1,3],[3,4],[5,6],[8,9],[14,0],[15,8]]
      > I want a code to test when the difference between the first element in
      > the list of list is equal to or larger than 6, then move the previous
      > lists to the end of the list. that is:
      > [[14,0],[15,8],[1,3],[3,4],[5,6],[8,9]][/color]


      your_list = [[1,3],[3,4],[5,6],[8,9],[14,0],[15,8]]


      for index, sublist in enumerate(your_ list):
      if abs(sublist[1] - sublist[0]) > 6:
      your_list = your_list[index:] + your_list[:index]
      break

      print your_list


      Bye,
      Dennis

      Comment

      Working...