Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 566 Bytes

for loop.markdown

File metadata and controls

19 lines (15 loc) · 566 Bytes

for loop and list

I have about 5 hunred books, and want to get some of their properties then compare them. The long program confused me on whether list of dict I should use. So I write them down here to give a clear thought.

lst = list()
for book in books:
    # get some properties in the book
    dict = book.properties
    lst.append(dict)

That is so easy!

  1. List definition before the list
  2. Properties are turned into dict
  3. Then the dict is appended to the list

If I have more hierachy level to compute, just make a iteration. So easy!