CSE 1010 Lecture Notes - Lecture 8: List Comprehension, 5,6,7,8
jadetortoise401 and 55 others unlocked
84
CSE 1010 Full Course Notes
Verified Note
84 documents
Document Summary
Cse notes 10/5/17: an alternative way to make fields. >>> [0 for i in range(4)] #list of four zeros. >>> f = [[0,0,0,0] for i in range(3)] [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]: when using list comprehension, result is list. >>> f = [[0 for i in range(4)] for j in range(3)] #make a list of three lists of four zeros: how to return values and what comes back, example fieldmaker. py def newfield(nrows, ncols): return [[0 for i in range(ncols)] for j in range(nrows)] Will run nine iterations: nested loops, write a python program that prints the following patterns separately one below the other. Use nested for loops to generate the patterns. Gnu nano 2. 2. 6 file: exl. py for i in range(10): for j in range(i+1): print("*", end=" ") print() for i in range(10): print("*" * (i+1): example 2.