python重复list中元素中的字母次数
来源:互联网 发布:ife矩阵结果分析 编辑:程序博客网 时间:2024/06/06 20:24
例如实现以下的情况:
words = ['hello', 'exercise', 'with', 'words']
repeat_letter(words, [4, 2, 10, -2], 3)
words = ['hello', 'exercise', 'with', 'words']
repeat_letter(words, [4, 2, 10, -2], 3)
#得到 ['helloooo', 'exeeeercise', 'with', 'wordddds']
def
repeat_letter(words, positions, times):
# 这里用了个Python切片特性的小技巧,w[p]如果p超出索引范围会报错。
# 但是如果写成w[p:p+1]就不会报错,而是返回一个w的空值,这样就免去了判断 if p < len(w) and p >= -len(w)
return
list
(
map
(
lambda
w,p: w[:p]
+
w[p:p
+
1
]
*
(times
+
1
)
+
w[p
+
1
:], words, positions))
words
=
[
'hello'
,
'exercise'
,
'with'
,
'words'
]
print
(repeat_letter(words, [
4
,
2
,
10
,
-
2
],
3
))
阅读全文
0 0
- python重复list中元素中的字母次数
- python中使用set去除list中的重复元素
- java统计List中的元素重复出现的次数
- 统计List中的元素重复出现的次数
- Python: 去除List中的重复元素
- python 去掉list中的重复元素
- 消去Python中list的重复元素
- Python 去除list中重复的元素
- python题目-----去除list中重复元素
- Python去除list中重复的元素
- python统计列表元素重复次数的N中方法
- python 统计list中各个元素出现的次数
- python 删除重复元素字典并在字典中加入重复元素次数
- python 去除 list 重复元素
- python 去除 list 重复元素
- 【Python】【List】去除列表中重复的元素
- Python中利用set去除列表(list)重复元素
- Python中利用set去除列表(list)重复元素
- 支持向量机SVM(4)
- 保险项目(特批名额维护功能)
- 【数据库】sql server中的作业
- iOS开发,plist文件读写那些事
- Cocos Code IDE 1.2.0 下载地址
- python重复list中元素中的字母次数
- 近5年133个Java面试问题列表
- mybatis插入与取出 blob clob字段
- 【JDK集合框架源码分析】-集合框架概述
- BaseRecyclerViewAdapterHelper源码解读(三) 添加动画
- 在Spring Boot框架下使用WebSocket实现消息推送
- Hadoop生态系统之Hive和HBase and Zookeeper
- 详解匿名内部类
- JAVA Spring HelloWord实现