How do I interpret the fancy loop in Python 2.7?

How does this line look like a regular 'for' loop?

inputList = [int(a) for a in inputList]

      

What are the advantages of writing a 'for' loop this way as opposed to being more vanilla?

+3


source to share


2 answers


new_list = []
for a in inputList:
    new_list.append(int(a))
inputList = new_list

      



Perhaps something like this.

0


source


I did something like this and it worked:



      enteredList = []
      for a in inputList:
          enteredList.append(int(a))

      

0


source







All Articles