[python]反转英文句子
2017-08-05 16:50
197 查看
def reverse(li, start, wl): i, j = start, start + wl - 1 while i < j: li[i], li[j] = li[j], li[i] i += 1 j -= 1 def fan(s): li = list(s) llen = len(li) start = 0 while (start < llen) and (li[start] == ' '):#第一个单词开始的位置 start += 1 while start < llen: #开始的位置 wl = 0 while ((start + wl) < llen) and (li[start + wl] != ' '):#将单词的长度找出来 wl += 1 reverse(li, start, wl) start += wl while (start < llen) and (li[start] == ' '): start += 1 li.reverse() return ''.join(li) s = " hello world " rs = fan(s) print(rs)
相关文章推荐
- java算法实现"输入一个英文句子,反转句子中的单词顺序,但单词内字符的顺序不变"
- 反转一个英文句子中的单词,并且对应位置大小写不改变
- python-在英文句子中查找单词并突出显示
- 字符串左旋 VS 反转英文句子
- 每日一题2:反转英文句子
- 反转英文句子内单词
- (Java)输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变,句子中单词以单个空格符隔开
- [leetcode, python] Reverse Words in a String 反转字符串
- 【python cookbook】 将字符串逐字符或逐词反转
- 16反转链表python
- Python中的反转字符串问题
- 用PIL(Python-Imaging)反转图像的颜色
- Python反转
- 字符串反转--句子反转和单词反转
- python判断unicode是否是汉字,数字,英文,或者其他字符
- [每天读一点英文:那些给我勇气的句子] the woman in the mirror
- python中从字符串中截取中文和英文字符
- [每天读一点英文:那些给我勇气的句子]:our kind landlord
- [每天读一点英文:那些给我勇气的句子]There are no mistakes, only lessons
- 免费Python技术图书汇总(英文)----http://jsbooks.revolunet.com/