map和dict之间的区别 [英] Difference between map and dict

查看:947
本文介绍了map和dict之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能会混淆Java中的 hashmap map / dict

我认为Java的哈希(k / v抽象)与<$ c相同Python中的$ c> dict

I might be confused between hashmap in Java, and map/dict in Python.
I thought that the hash (k/v abstraction) of Java is kind of the same as dict in Python

但是 map 数据类型有什么作用?

But then what does the map datatype do?

它与哈希图抽象相同吗?如果是这样,那么它与字典有什么不同?

我浏览了文档,但是却把我带到了一起,形成了不同的范例:函数式编程。

Is it the same abstraction as the hashmap abstraction? If so, then how is it different from dictionary?
I went through the docs, but it took me to whole together different paradigm: functional programming.

推荐答案

地图不是数据类型在python中。它将函数应用于一系列值并返回结果。

Map is not a datatype in python. It applies a function to a series of values and returns the result.

>>> def f(x):
...     return x**2
... 
>>> list(map(f, range(5)))
[0, 1, 4, 9, 16]

通常,对于像 pythonic这样的简单情况,我们使用列表推导。

Often for a simple case like that to be "pythonic" we use list comprehensions.

>>> [x**2 for x in range(5)]
[0, 1, 4, 9, 16]

您在比较哈希图和字典时是正确的。

You are right in your comparison of hashmaps and dicts.

这篇关于map和dict之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆