0

i am trying to print out a list of string and integers vertically.

map = [["SG", 8], ["MY", 8], ["PH", 8], ["ID", 8], ["TH", 8]]

the print should return:

SG        8
MY        8
PH        8
ID        8
TH        8

this is what i have :

for element in map:
  print(element)

the failed output:

    ['SG',       8]  
    ['MY',       8]  
etc....
PM 77-1
  • 12,933
  • 21
  • 68
  • 111
m4ti666
  • 1
  • 2

1 Answers1

2

May note be the best solution, but try this.

for element in map:
    print("{}\t{}".format(element[0],element[1]))
FelipeCruzV10
  • 426
  • 6
  • 13
  • `element` != `i` – azro Aug 02 '21 at 17:27
  • Oh yeah sorry, I've already corrected – FelipeCruzV10 Aug 02 '21 at 17:31
  • you can do `for a,b in map` to already unpack – azro Aug 02 '21 at 21:06
  • yeah sure, at the end is the same. I think that the person who asked this was looking for something like the "\t" which is useful when the first element is always the same size, or something like "%-8s %2d" for other cases. That is, learning a bit of python string formatting. – FelipeCruzV10 Aug 02 '21 at 21:31
  • i have managed to print it out vertically, now my next problem is that for every turn, i will have 2 inputs in which i have to choose eg sg,my , my,ph, th,sg, and i would have to select 1 of them in each turn. how would i check to see if i picked sg it will print out SG 7? so basically if u picked an item, it would be deducted by 1 – m4ti666 Aug 03 '21 at 09:10
  • That is already another question. You can ask ask a new question for that. – FelipeCruzV10 Aug 03 '21 at 23:43