Newbie question regarding string.split()

Stephen Lewitowski stephen04 at tiscali.co.uk
Fri Apr 20 15:26:52 EDT 2007


kevinliu23 wrote:
> Hey guys,
> 
> So I have a question regarding the split() function in the string
> module. Let's say I have an string...
> 
> input = "2b 3 4bx 5b 2c 4a 5a 6"
> projectOptions = (input.replace(" ", "")).split('2')
> print projectOptions
> 
> ['', 'b34bx5b', 'c4a5a6']
> 
> My question is, why is the first element of projectOptions an empty
> string? What can I do so that the first element is not an empty
> string? but the 'b34bx5b' string as I expected?
> 
> Thanks so much guys. :)
> 
split on c instead



More information about the Python-list mailing list