-1

I'm new to programming, and I'm trying to solve this, how can I make a range for the elements in my list?

example:

list = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
test = range(list[0], list[11])
print test

result:

[]

How to put the list elements from 0 to 11 in test?

YakovL
  • 7,557
  • 12
  • 62
  • 102
  • Possible duplicate of [Understanding Python's slice notation](https://stackoverflow.com/questions/509211/understanding-pythons-slice-notation) – Azat Ibrakov Nov 18 '18 at 08:09
  • range is used for generating a range of subsequent integers with a certain step between 2 numbers; if you need to pick elements from another array, you should use slicing instead, see the link by Azat – YakovL Nov 18 '18 at 09:59
  • 3
    This is not reproducible, `test` isn't empty it is a populated list – Chris_Rands Nov 19 '18 at 09:47

1 Answers1

0

See if you want to create a new list with elements 0 to 11 as integers, you can directly use the below method:

   test = range(0,12)

If you want to access data from existing list, you should use splice as shown below:

    test = list[0:12]
Shagun Pruthi
  • 1,813
  • 15
  • 19