What I want to do, is transform my variable:
table = "female\tIngelin\tAleksandersen\nmale\tJohnny\tDigre\nmale\tOsman\tBremseth\nfemale\tCathrine\tDagestad\nfemale\tTirill\tBakker"
Into a kind of scheme like this:
- Row: 0 Col: 0 Cell value: female
- Row: 0 Col: 1 Cell value: Ingelin
- Row: 0 Col: 2 Cell value: Aleksandersen
- Row: 1 Col: 0 Cell value: male
- Row: 1 Col: 1 Cell value: Johnny
The list is long, so ill stop at 5, but you get the point. My code so far:
table="female\tIngelin\tAleksandersen\nmale\tJohnny\tDigre\nmale\tOsman\tBremseth\nfemale\tCathrine\tDagestad\nfemale\tTirill\tBakker"
def show_table():
print(table)
def show_every_cell():
col = -1
row = -1
names = table.split("\t")
for x in names:
row += 1
if row == 0:
col += 1
if col == 0:
print('Row: 0 Col: 0 ' + 'Cell value: ' + x)
if col == 1:
print('Row: 0 Col: 1 ' + 'Cell value: ' + x)
if col == 2:
print('Row: 0 Col: 2 ' + 'Cell value: ' + x)
if row == 1:
col += 1
if col == 0:
print('Row: 1 Col: 0 ' + 'Cell value: ' + x)
if col == 1:
print('Row: 1 Col: 1 ' + 'Cell value: ' + x)
if col == 2:
print('Row: 1 Col: 2 ' + 'Cell value: ' + x)
#The list continues with row: 2, 3 and 4. But no point in showing that part.
def main():
show_table()
show_every_cell()
if __name__ == "__main__":
main()
My output is this:
Row: 0 Col: 0 Cell value: female
Row: 1 Col: 1 Cell value: Ingelin
As you see, it misses quite a lot....