0

How do i split

how do i split DoYourHomework to Do Your Homework

3rd Nov 2016, 6:34 PM
alex slater
alex slater - avatar
5 Respostas
+ 1
List comprehension. It's basically a collapsed loop. I couldn't find any examples online (and I'm new to Python) so please excuse it if messy/bad vs RegEx. >>> a="DoYourHomework" >>> "".join([" "+z if z.isupper() else z for z in list(a)]).strip() 'Do Your Homework' By the way, for ASCII: bit 6 is 0 in uppercase, 1 in lowercase if someone thinks that's useful.
4th Nov 2016, 1:07 AM
Kirk Schafer
Kirk Schafer - avatar
0
string.split() function will not work in this case because of zero-width match. use regular expressions instead: import re str = 'DoYourHomework' lst = re.findall('[A-Z][^A-Z]*', str) print (lst)
3rd Nov 2016, 6:43 PM
Demeth
Demeth - avatar
0
is there any other way?
3rd Nov 2016, 9:08 PM
alex slater
alex slater - avatar
0
maybe there is, but this one seems to be very simple and convenient. you can, of course, search through the string in loop, check if letter is capital etc., but that's not a good strategy.
3rd Nov 2016, 9:21 PM
Demeth
Demeth - avatar
0
i was just wondering because i havent learned about regular expressions so i dont know all the applications it carries
3rd Nov 2016, 9:27 PM
alex slater
alex slater - avatar