tags:

views:

121

answers:

2

I have a string a and I would like to split it in half depending on its length, so I have

a-front = len(a) / 2 + len(a) % 2

this works fine in the interpreter but when i run the module from the command line python gives me a SyntaxError: can't assign to operator. What could be the issue here.

+2  A: 

You might mistype hyphen and underscore, try

a_front = len(a) / 2 + len(a) % 2
S.Mark
Yeah that worked. Figured out that - is the minus operator
mzee
A: 

It's more pythonic this way:

a = "foo bar baz"
front = a[:len(a)/2]               # integer division with truncating
front = a[:int(round(len(a)/2.0))] # float division with rounding
mawimawi