美文网首页
python逆置单词的三种方式(字符串同理)

python逆置单词的三种方式(字符串同理)

作者: a嘿嘿_ccee | 来源:发表于2020-06-02 22:04 被阅读0次
str = "this is a good day"
list = str.split()
print(list)
temp = []
flag = 0
while len(list)>0:
    temp.append(list.pop())
print(temp)



str = 'this is a good day'
list = str.split()
lo = 0
hi = len(list)-1
while lo<hi:
    temp = list[lo]
    list[lo] = list[hi]
    list[hi] = temp
    lo+=1
    hi-=1
print(list)

str = 'this is a good day'
list = str.split()
def reserve(list, lo, hi):
    if lo<hi:
        temp = list[lo]
        list[lo] = list[hi]
        list[hi] = temp
        reserve(list, lo+1, hi-1)
reserve(list, 0, len(list)-1)
print(list)

相关文章

  • python逆置单词的三种方式(字符串同理)

  • 傻逼快看

    2.确定单词的个数。查找指定的字符。 3.字符串的逆置 4.字符串的连接 要将s所指的字符串存入a所指的字符串中,...

  • python字符串高级拼接

    python中字符串拼接有三种方式 方式一: + 不推荐使用 方式二: 打印 % 或者 format 方式三:专为...

  • Python字符串操作

    一、字符串格式化 Python有三种字符串格式化方法:百分号方式,format方式,模板方式 1、百分号方式 2、...

  • c++算法常用函数

    利用sort函数排序: sort(arr,arr+index); 字符串逆置函数: _strrev()...

  • 量化交易入门笔记-Datetime和Time模块

    Python 中,通常有三种方式用来表示时间,分别是时间戳、格式化的字符串、元组(struct_time)方式 时...

  • 2018-05-25

    python 1.python中数组和矩阵乘法及使用总结 对数组的运算 矩阵求逆,转置,求迹

  • python 求次方

    推荐阅读 1 python pow() 函数 | 菜鸟教程 python求次方的三种方式 三种方式的区别 我试图在...

  • python3 判断类型是否为空

    python 判断数组、字符串、对象、字典等是否为空? 字符串为空判断 打印 其他常量判断 同理字符串 这些都是f...

  • python 二进制中1的个数-算法比较

    分别使用三种方式进行计算 转化为字符串,数‘1’ ,Python的原生库支持 引入 gmpy 库, 使用其中的po...

网友评论

      本文标题:python逆置单词的三种方式(字符串同理)

      本文链接:https://www.haomeiwen.com/subject/gexmzhtx.html