社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

Python搜索2d数组并返回if found和index found

Super Sonic • 5 年前 • 1489 次点击  

我有一个二维数组,可能包含数据,也可能不包含数据。首先我要搜索包含特定数据的索引,如果为true,则更新数组中的数据。

到目前为止,我已经成功地搜索了这个数组,并在找到索引时返回了一个true或false语句。但是我还需要返回索引值,这样我就可以修改和更新数组中的数据。

from itertools import chain
self.asset= [[]]

def findIn2dArray(self, arr, value):
    return value in chain.from_iterable(arr)

if self.findIn2dArray(self.asset, element.get("asset")):
     print("found updating")
     self.asset[???, 1] = new updated value

我知道哪些列需要更改,但我不知道数据的索引位置,希望这有意义。如果findIn2dArray函数也返回索引号,那就太好了,谢谢!

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52196
 
1489 次点击  
文章 [ 1 ]  |  最新文章 5 年前