do looping from N to 1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nischalinn
    New Member
    • Mar 2014
    • 16

    do looping from N to 1

    Suppose I've some user-defined lists:
    Say,

    [1,2,3,5,6,8]
    [1,2,3,4,5,6,7,8 ,9,10]

    Suppose I've to split the list using user defined number, say N =3 for the first list.
    Then the output will be:

    for N = 3 [1,2,3]
    for N-1 = 2 [5,6]
    for N -2 = 1 [8]

    say N =4 for the second list.
    Then the output will be:

    for N = 4 [1,2,3,4]
    for N-1 = 3 [5,6,7]
    for N -2 = 2 [8,9]
    for N-3 = 1 [10]

    So looping from N to 1. How can I get the output.
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Just a hint, but this is enough info to figure out the logic. And you should use a for or while loop to do it.
    Code:
    x=[1,2,3,4,5,6,7,8,9,10]
    n=4
    group=n
    previous=0
    print x[previous:n]
    previous = n
    group -= 1
    n += group
    print x[previous:n]

    Comment

    Working...