HOME | Blog | YouTube | LinkedIn | About Me         || Calculators    | SoftEng/Tech Posts    | Code/Scripts

Python - Append to List and Traverse the list - Different ways of doing it



#!/usr/bin/python
#####################################################################
def main():
    myList = loadList()
    for index, item in enumerate(myList):
        print index, item
        if index == 5:
            break
    print "----------"

    for k, theitem in enumerate(myList):
        print k, theitem

    print "---------------------"
    myList_Two = loadAnotherList()
    for j in range(0, len(myList_Two)):
        print myList_Two[j]
        if j == 7:
            break
    print "----"
    for m in range(0, len(myList_Two)):
        print myList_Two[m]

#####################################################################
def loadList():
    for i in range(1,10):
        s = str(i) + "testing"
        yield s

#####################################################################
def loadAnotherList():
    myList2 = []
    for i in range(1, 10):
        s = str(i) + "performing"
        myList2.append(s)

    return myList2

#####################################################################
if __name__ == "__main__": main()



- almirsCorner.com -

#python #programming #code #coding #software #softwaredeveloper #softwareengineering #programmer

No comments:

Post a Comment