Home python Python Formatting List Output

Python Formatting List Output

Author

Date

Category

How to display the list in the Return function – like this?

ok 1
OK 2.
OK 3.
Not ok 4.

Now the list is displayed like this:

[ok ', 1], [' ok ', 2], [' ok ', 3] ['not OK', 4]]

Function itself

def msg ():
MES = []
FOR NUMBER IN [1,2,3,4]:
  IF Number & LT; 4:
    MES.APPEND (['OK', Number])
  ELSE:
    Mes.APPEND (['not OK', Number])
Return Mes.

UPD:

def msg ():
  MES = []
  FOR NUMBER IN [1,2,3,4]:
    IF Number & LT; 4:
      Mes.APPEND (''. Join (MAP (STR, ['OK -', Number])))
    ELSE:
      Mes.APPEND (''. Join (MAP (STR, ['not OK -', Number])))
  Return Mes.

output & gt; & gt; ['ok - 1', 'ok - 2', 'ok - 3', 'not ok - 4']

you need to transfer the strings to be


Answer 1, Authority 100%

That’s how:

def msg ():
  MES = []
  FOR NUMBER IN [1,2,3,4]:
    IF Number & LT; 4:
      MES.APPEND (['OK', Number])
    ELSE:
      Mes.APPEND (['not OK', Number])
  Return Mes.
For x, y in msg ():
  Print (x, y)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions