代码
import string
def to_camel_case(text):
print text
word=list(text)
for i in range(0,len(word)-2):
if word[i]=='-' or word[i]=='_' or word[i]=='=':
word[i+1]=word[i+1].upper()
#del(word[i])#用红字将会出现out of range 的情况
#i=i-1
a=''
for x in word:
if x=='-' or x=='_' or x=='=':
a=a
else:
a+=x
return a
测试代码
test.describe("Testing function to_camel_case")
test.it("Basic tests")
test.assert_equals(to_camel_case(''), '', "An empty string was provided but not returned")
test.assert_equals(to_camel_case("the_stealth_warrior"), "theStealthWarrior", "to_camel_case('the_stealth_warrior') did not return correct value")
test.assert_equals(to_camel_case("The-Stealthtext=Warrior"), "TheStealthWarrior", "to_camel_case('The-Stealth-Warrior') did not return correct value")
test.assert_equals(to_camel_case("A-B-C"), "ABC", "to_camel_case('A-B-C') did not return correct value")
1.不能直接用‘=’对字符串进行修改,必须使用相关函数。为了方便修改,最好将其列表化。对于一整个字符串,需使用list(string),而对于字符串块,则可以使用string.split().
2.小写转化成大写用.upper。大写转化成小写用.lower。
3.对于数组中删除某个元素这一点,我实在是掌握不好i的取值,与其这样,不如灵活使用字符串的+,以及数组的append。
4.学习不好好想死啊。。。