通过 jupyter notebook 来执行更新 hexo
本文最后更新于 2025-12-03,文章内容可能已经过时。
date: 2022-05-30 05:45:40
通过jupyter notebook来执行hexo g/d
!cd /blog/ &&./g.sh
jpyter安装主题
!pip install --upgrade jupyterthemes
!jt -t oceans16 -f fira -fs 12 -cellw 90% -ofs 10 -dfs 11 -T
反转字符串
切片方式反转
strn = "Hello world!";
s1 = strn[::-1]
print(strn,'\n','*'*10)
print(s1)
Hello world!
**********
!dlrow olleH
通过 reversed()+join()方法反转
s2 = reversed(strn)
print(strn,'\n','*'*10)
print(''.join(s2))
Hello world!
**********
!dlrow olleH
通过函数实现
def reversed_string(text):
result = ''
for char in text:
result = char +result
return result
print(strn,'\n','*'*10)
print(reversed_string(strn))
Hello world!
**********
!dlrow olleH
使用reduce实现
from functools import reduce
def reversed_string_reduce(text):
return reduce(lambda a, b: b + a, text)
print(strn,'\n','*'*10)
print(reversed_string_reduce(strn))
Hello world!
**********
!dlrow olleH
python内置函数
list_test = ['a1','a2','a','3','a','4']
print(list_test)
print(' '.join(reversed(list_test)))#反转
print(list(enumerate(list_test)))#组合成索引序列
print(sorted(list_test))#排序
['a1', 'a2', 'a', '3', 'a', '4']
4 a 3 a a2 a1
[(0, 'a1'), (1, 'a2'), (2, 'a'), (3, '3'), (4, 'a'), (5, '4')]
['3', '4', 'a', 'a', 'a1', 'a2']
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 纪梦鱼
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果
音乐天地

