一直想写博客,犹犹豫豫,就从此刻开始吧
IDE:jupyter notebook
题目来源:《交通时空大数据分析、挖掘与可视化》 2.6.2 T6
a = "ASWs NvDIuCLOEUYVoe"
b = "8.4.11.-2.6.18.4.-4.-2.9"
b = b.split('.')
b = ''.join(list(map(lambda x:a[int(x)],b)))
b
运行结果:'I Love You'
step1:
map(lambda x:a[int(x)],b)
在创建map时传入一个匿名函数和字符列表b,匿名函数将以b各元素的数值为索引找到a中对应的字符。
到这里在python2中会返回一个修改后的字符列表,但是在python3中只会返回一个迭代器。
参考: Python3中利用map将列表当中的string类型转换为int类型或其它类型_python map string to int_Y4tacker的博客-CSDN博客
step2:
list(map(lambda x:a[int(x)],b))
将其转换为list,得到一个列表。
step3:
b = ''.join(list(map(lambda x:a[int(x)],b)))
将list转为str,并赋值给b