Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I'm new to python and need to make a list with a negative index however has not been effective up until now. 

I'm utilizing this code

a = []

for i in xrange( -20, 0, -1 ):

    a[i] = -(i)

    log.info('a[{i}]={v}'.format(i=i, v=a[i]))

else:

    log.info('end')

But I'm getting the log output as:

end

Unexpectedly I'm utilizing a webpage call Quantopian so the log.info is from their foundation and simply prints out the yield into a web console.

Where I went wrong?

Thankyou in advance

1 Answer

0 votes
by (26.4k points)

On the off chance that you are utilizing Quantopian, it is fitting that you become acquainted with numpy and pandas. For instance

>>> import numpy as np 

>>> -1*np.arange(20)

array([  0,  -1,  -2,  -3,  -4,  -5,  -6,  -7,  -8,  -9, -10, -11, -12,

       -13, -14, -15, -16, -17, -18, -19])

Later, you will have a[1]==-1, a[5]==5, etc.

Looking for a good python tutorial course? Join the python certification course and get certified.

For more details, do check out the below video tutorial...

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
+3 votes
2 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...