-2

The problem with the code is that the code run once only for i=0 .It is not repeating for next index.Why?


list1=['shukla928','kavita_patel7']
list2=['7379561059','kavitapatel9ptl']

for i in range(0,1):
    session=InstaPy(username=list1[i],password=list2[i],headless_browser=True)
    session.login()

    session.set_relationship_bounds(enabled=True, max_followers=500)


    session.set_do_follow(enabled=True, percentage=100, times=2)
    session.follow_by_list(followlist=['pankaj_patel63'], times=2, sleep_delay=60, interact=False)
    # session.end()```



  • There is no next index. `range(0, 1)` is equivalent to `[0]`. – Selcuk Feb 11 '21 at 06:31
  • `for i in range(0,1)` will run only for i=0 by default. If you want to run for i=1 change it to `for i in range(0,2)` – IoaTzimas Feb 11 '21 at 06:31
  • Replacing range(0, 1) to range(0, 2) makes more sense. – shiv_90 Feb 11 '21 at 06:32
  • 1
    It's often nicer to iterate directly over the list elements instead of the indices. Here you could do `for username, password in zip(list1, list2)` (and probably rename your lists to be something like `usernames` and `passwords`). – Nathan Feb 11 '21 at 06:44

1 Answers1

1

range(i,j) implies run from i to j-1.

So, range(0,1) implies run from 0 to 0 so it runs just once.

You could use range(0,len(list1)) if both lists have same lengths.

Krishna Chaurasia
  • 8,924
  • 6
  • 22
  • 35