0

Given the string:

str = 'Led Zeppelin — Blackdog'

how do I split it at , ending up with:

['Led Zeppelin', 'Blackdog']

but is not an hyphen; it is encoded as u'\u2014'

how do I do it?

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
8-Bit Borges
  • 9,643
  • 29
  • 101
  • 198

1 Answers1

1

You can just split on explicitly what you've provided if you want it to be clear that it is not a hyphen, surrounded by a whitespace character if that is standard-included with the character. Also, don't shadow built-ins with str as a variable name.

>>> s = 'Led Zeppelin — Blackdog'
>>> s.split(u' \u2014 ')
['Led Zeppelin', 'Blackdog']
>>> s.split(' — ') # perhaps less explicit
['Led Zeppelin', 'Blackdog']
Community
  • 1
  • 1
miradulo
  • 28,857
  • 6
  • 80
  • 93