[英]data manipulation/ indexing python vs R
I am inexperienced with python and am unsure what i should search for this particular task. 我对python没有经验,不确定我应该搜索什么特定任务。 I am trying to find a way to index a list much like i would index a vector in R:
我正在尝试找到一种索引列表的方法,就像我在R中对向量进行索引一样:
vec=c(1,2,3)
> vec==1
[1] TRUE FALSE FALSE
>>> list_a=[1,2,3]
>>> list_a==1
False
for i in list_a:
... i==1
...
False
False
False
Notice above that it is False for all three values even though the first value is 1??? 请注意,即使第一个值为1,对于所有三个值均为False。
>>> for i in list_a:
... if i==1:
... print('hello')
...
hello
Hence when it comes to python I am just looking for a way to index the the python list in the same way as i can I'm R??? 因此,当涉及到python时,我只是在寻找一种索引python列表的方法,就像我可以使用R一样???
What about : 关于什么 :
>>> [x == 1 for x in list_a]
[True, False, False]
an alternative: 替代:
map(lambda x: x == 1, list_a)
#[True, False, False]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.