I'm trying to separate the rows into three different lines but I'm having trouble figuring out how to do it. Code is below.
row1 = [{'name':'Wes','absences': 2}, {'name':'Jack','absences': 6},{'name':'Chris', 'absences':8}]
row2 = [{'name':'Justin','absences':1}, {'name':'Josh','absences':12}, {'name':'Matt','absences':3}]
row3 = [{'name':'Jake','absences':4}, {'name':'Jon','absences':2}, {'name':'Kippen','absences':15},{'name':'Jose','absences':7}]
classroom = row1,row2,row3
print (classroom)
CodePudding user response:
You can use the unpacking operator with a newline separator:
print(*classroom, sep='\n')
This outputs:
[{'name': 'Wes', 'absences': 2}, {'name': 'Jack', 'absences': 6}, {'name': 'Chris', 'absences': 8}]
[{'name': 'Justin', 'absences': 1}, {'name': 'Josh', 'absences': 12}, {'name': 'Matt', 'absences': 3}]
[{'name': 'Jake', 'absences': 4}, {'name': 'Jon', 'absences': 2}, {'name': 'Kippen', 'absences': 15}, {'name': 'Jose', 'absences': 7}]
CodePudding user response:
You can also use \n when creating the variable with an f string.
classroom = f"{row1}\n{row2}\n{row3}"
print(classroom)