为什么in返回数组的值和字典的键 [英] why in returns values for array and keys for dictionary

查看:104
本文介绍了为什么in返回数组的值和字典的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




对于

数组和词典的'返回值'(或键)来说不是更好吗? 。在我学习这种差异之前,数组和字典看起来非常相似。


谢谢,

++ imanshu

推荐答案

8月26日,10:49 * am,++ imanshu < himanshu.g ... @ gmail.comwrote:
On Aug 26, 10:49*am, "++imanshu" <himanshu.g...@gmail.comwrote:

* *没有更好的''in''返回值(或键) )对于两个

数组和字典。在我学习这种差异之前,数组和字典看起来非常类似于
Python。
* * Wouldn''t it be nicer to have ''in'' return values (or keys) for both
arrays and dictionaries. Arrays and Dictionaries looked so similar in
Python until I learned this difference.



通过''arrays''你的意思是列表吗?元组?


我不确定你怎么找到列表&类似的词典...

By ''arrays'' do you mean lists? tuples?

I''m not sure how you''d ever find lists & dictionaries similar...


>> alist
>>alist



[1,2,3]

[1, 2, 3]


>> adict
>>adict



{''a'':1,''c'':3 ,'''':2}


一个是一个序列,具有便利功能,可以将它视为一个

堆栈或队列。

另一个是键和对之间的映射。


在这两种情况下,''in''返回一个布尔值,表示存在一个
$ b列表中的$ b项,或者dict中的键。我不确定你为什么需要它

返回你检查存在的项目,因为你有

到在你做检查之前有这个项目。


我错过了你在这里要求的东西吗?你能提供一个

伪代码示例来证明你的意思吗?

{''a'': 1, ''c'': 3, ''b'': 2}

One is a sequence, with convenience functions for treating it like a
stack or a queue.
The other is a mapping between keys and pairs.

In both cases, ''in'' returns a boolean indicating the existence of an
item in the list, or a key in the dict. I''m not sure why you''d need it
to return the item you''re checking for the existence of, as you''d have
to have that item before you could do the check.

Have I missed what you''re asking for here? Could you provide a
pseudocode example to demonstrate what you mean?


8月26日,12:57 * pm,alex23< wuwe。 .. @ gmail.comwrote:
On Aug 26, 12:57*pm, alex23 <wuwe...@gmail.comwrote:

通过''arrays''你的意思是列表吗?元组?
By ''arrays'' do you mean lists? tuples?



道歉,实际上是Python中的数组类型。


我老实说从来没有过任何使用它的原因:)


我仍​​然不完全确定你想要做什么'。'

My apologies, there actually -is- an array type in Python.

I''ve just honestly never had any cause to use it :)

I''m still not entirely sure what you would like ''in'' to do, though.


8月25日,9:57 * pm,alex23< wuwe ... @ gmail.comwrote:
On Aug 25, 9:57*pm, alex23 <wuwe...@gmail.comwrote:

8月26,10:49 * am,++ imanshu < himanshu.g ... @ gmail.comwrote:
On Aug 26, 10:49*am, "++imanshu" <himanshu.g...@gmail.comwrote:

* *没有更好的''in''返回值(或键) )对于两个

数组和字典。在我学习这种差异之前,数组和字典看起来非常类似于
Python。
* * Wouldn''t it be nicer to have ''in'' return values (or keys) for both
arrays and dictionaries. Arrays and Dictionaries looked so similar in
Python until I learned this difference.



''数组''你的意思是列表吗?元组?


我不确定你怎么找到列表&类似的词典...


By ''arrays'' do you mean lists? tuples?

I''m not sure how you''d ever find lists & dictionaries similar...


> alist
>alist



[1,2,3]

[1, 2, 3]


> adict
>adict



{''a'':1,''c'':3,''b'':2}


一个序列,方便用于处理它的函数就像一个

堆栈或队列。

另一个是键和对之间的映射。


{''a'': 1, ''c'': 3, ''b'': 2}

One is a sequence, with convenience functions for treating it like a
stack or a queue.
The other is a mapping between keys and pairs.



你可以说列表也是键和对之间的映射,

,其约束条件必须是键的整数0到

len(x)-1。也就是说,['''',''b'',''c'']就像{0:''a'',1:''b'',2:''c''},

至少就[]运算符和len函数而言。

You could argue that lists are also a mapping between keys and pairs,
with the constraint that the keys have to be the integers from 0 to
len(x)-1. That is, [''a'', ''b'', ''c''] is like {0: ''a'', 1: ''b'', 2: ''c''},
at least as far as the [] operator and the len function are concerned.


这篇关于为什么in返回数组的值和字典的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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