0

I have a list with special characters like l1 = ['øk', 'løk', 'pølse', 'pål', 'æl'] How can I print or return this list in a function so the special characters are included. I know you can write print u'Ølske'

but what do you do when you have lists?`

When I run this:

# -*- coding: utf-8 -*-
l1 = [u"ål", u"øk", u"møk"]

print l1

I get:

[u'\xe5l', u'\xf8k', u'm\xf8k']
user3297266
  • 45
  • 1
  • 6

1 Answers1

0

Here's the small hack that will do the job:

>>> l1 = [u"ål", u"øk", u"møk"]
>>> print '[' + ', '.join("'" + x + "'" for x in l1) + ']'
>>> ['ål', 'øk', 'møk']

Python 3.0 should print the special characters as is from the list without any hassles.

Shan Valleru
  • 3,093
  • 1
  • 22
  • 21