Skip to content

Commit e1d783c

Browse files
committed
modify one mistake
1 parent 4f6583c commit e1d783c

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

string_to_hump.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,26 @@
77
#解决
88

99
##python解决方法:
10-
#! /usr/bin/env python
11-
#coding:utf-8
12-
1310
def convert(one_string,space_character): #one_string:输入的字符串;space_character:字符串的间隔符,以其做为分隔标志
14-
11+
1512
string_list = str(one_string).split(space_character) #将字符串转化为list
13+
first = string_list[0].lower()
14+
others = string_list[1:]
15+
16+
others_capital = [word.capitalize() for word in others] #str.capitalize():将字符串的首字母转化为大写
1617

17-
string_hump_list = [word.capitalize() for word in string_list] #str.capitalize():将字符串的首字母转化为大写
18+
others_capital[0:0] = [first]
1819

19-
hump_string = ''.join(string_hump_list) #将list组合成为字符串,中间无连接符。驼峰样式
20+
hump_string = ''.join(others_capital) #将list组合成为字符串,中间无连接符。
2021

2122
return hump_string
2223

2324
if __name__=='__main__':
25+
print "the string is:ab-cd-ef"
26+
print "convert to hump:"
2427
print convert("ab-cd-ef","-")
25-
28+
2629

2730
##欢迎补充其它语言的解决方法
31+
32+
#联系我:老齐 qiwsir#gmail.com (# to @)

string_to_hump.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
def convert(one_string,space_character): #one_string:输入的字符串;space_character:字符串的间隔符,以其做为分隔标志
55

66
string_list = str(one_string).split(space_character) #将字符串转化为list
7+
first = string_list[0].lower()
8+
others = string_list[1:]
79

8-
string_hump_list = [word.capitalize() for word in string_list] #str.capitalize():将字符串的首字母转化为大写
10+
others_capital = [word.capitalize() for word in others] #str.capitalize():将字符串的首字母转化为大写
911

10-
hump_string = ''.join(string_hump_list) #将list组合成为字符串,中间无连接符。驼峰样式。
12+
others_capital[0:0] = [first]
13+
14+
hump_string = ''.join(others_capital) #将list组合成为字符串,中间无连接符。
1115

1216
return hump_string
1317

1418
if __name__=='__main__':
19+
print "the string is:ab-cd-ef"
20+
print "convert to hump:"
1521
print convert("ab-cd-ef","-")

0 commit comments

Comments
 (0)