trouble to print array contents using slice operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • praba kar

    #1

    trouble to print array contents using slice operator

    Dear all,

    In Php array_slice function base
    we can print array contents as per our desire
    eg)

    $a = array(1,2,3,4,5 ,6,7,8,9,10,11, 12,13,14,15);
    $arr = array_slice($a, 10,10);

    this function will print 11,12,13,14,15

    But I try to print the same thing in python
    using slice operator

    eg) print a[10:10]

    This statement print [] empty array.

    How I need to get my desired output like php
    array_slice function?

    with regards
    Prabahar





    _______________ _______________ _______________ _______________ ____________
    Yahoo! India Matrimony: Find your life partner online
    Go to: http://yahoo.shaadi.com/india-matrimony
  • Diez B. Roggisch

    #2
    Re: trouble to print array contents using slice operator

    praba kar wrote:
    [color=blue]
    > Dear all,
    >
    > In Php array_slice function base
    > we can print array contents as per our desire
    > eg)
    >
    > $a = array(1,2,3,4,5 ,6,7,8,9,10,11, 12,13,14,15);
    > $arr = array_slice($a, 10,10);
    >
    > this function will print 11,12,13,14,15
    >
    > But I try to print the same thing in python
    > using slice operator
    >
    > eg) print a[10:10]
    >
    > This statement print [] empty array.
    >
    > How I need to get my desired output like php
    > array_slice function?[/color]

    Slicing indices in python are [start:stop], not [start:lengh]. So use

    print a[10:10+10]




    --
    Regards,

    Diez B. Roggisch

    Comment

    Working...