David Silva
David Silva

Reputation: 2017

Return a tuple of arguments to be fed to format()

How I can fix it?

return 'loader:\n {}' % ''.join('{}:{}\n'.format(*(key, value) for key, value in slownik.iteritems()))

SyntaxError: invalid syntax

this should be in one line ;-)

Upvotes: 0

Views: 66

Answers (2)

Burhan Khalid
Burhan Khalid

Reputation: 174624

'loader: \n '+''.join('{0}:{1}\n'.format(k,v) for k,v in slownik.iteritems())

Upvotes: 1

Fred Foo
Fred Foo

Reputation: 363547

Drop the '%', which is the old-style string formatter; drop the generator comprehension, because iteritems returns exactly what you need to do formatting; finally, drop the double format:

'loader:\n {0}:{1}\n'.format(*slownik.iteritems())

EDIT: ok, now I see what you want to do.

'loader:\n' + ''.join(' {0}:{1}\n'.format(k, v)
                      for k, v in slownik.iteritems())

Upvotes: 5

Related Questions