[英]How to convert String into list of character while using lambda and map function?
[英]How to convert the perl code to python using map and lambda function
我在 perl 中有代码,如下所述:
%details_hash = map { $_ => $_ } split(/\\s+/, $details_data);
它需要一个字符串,根据空间分割它并创建一个具有相同键和值的哈希。 我需要在 python 中重写相同的代码并创建一个字典。
s = 'Hello world!'
print dict( (k,k) for k in s.split() )
输出:
{'world!': 'world!', 'Hello': 'Hello'}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.