Sunday, March 20, 2011

How to pass value for python for loop?

In C/C++:

for(int i=0;i<=5;i++)

In Python:

for i in range(0,5)

Question is:

s=[1,2,3,4,1]

for i in s:
    for j in s:

Here i wanna make second for loop j=1 (j value should be start with 1 like this s[1]=2).How do i pass that value.

From stackoverflow
  • You should ask this on stackoverflow, but the answer is (if I got you right):

    for i in s:
       for j in s[1:]:
    

    Read this chapter about lists in python, this will help you.

    Felix Kling : If the solution helps you, select the checkmark beside this answer.

0 comments:

Post a Comment