-3

Hi i am new to python and i am trying to build a function which will select each element of the list at a time,store each element in a variable and do something (using a loop)

StrLst = ['aaa','bbbaaa','cccbbb','aaabbb']

now i want the first element of the list which will be stored in a variable

LstEle = list[0]    #i.e. LstEle = aaa

use the LstEle variable

and then go to the next element and do the same keep doing this for the whole list

Kevin
  • 74,910
  • 12
  • 133
  • 166
Tanmay
  • 3
  • 5

1 Answers1

2

You can use a for-loop in order to achieve what you want.

for LstEle in StrLst:
    # do something with LstEle

In each iteration the current element will be accessible through LstEle.

ConfusedProgrammer
  • 606
  • 1
  • 5
  • 14
  • how do you iterate to each element i.e. change the value in list [] brackets – Tanmay Sep 15 '14 at 17:18
  • It's iterating automatically because lists in python are iterable objects. I know this is question-answer site but I strongly suggest to read any of introducing into python book or internet tutorial. – python Sep 15 '14 at 17:20
  • @Tanmay also, learn to search: http://stackoverflow.com/q/4081217/3001761 – jonrsharpe Sep 15 '14 at 17:21