Python.多维数组的索引

2024-09-29 23:24:06 发布

您现在位置:Python中文网/ 问答频道 /正文

arrrSample =

 {'art_other_country_names': None, 
  'pk_ba_country_id': 186,
  'sin_active': 1,
  'txt_remarks': '',
  'vhr_common_country_name': 'Uzbekistan',
  'vhr_formal_country_name': 'Republic of Uzbekistan',
  'vhr_nationality': '',
  'vhr_short_country_name': '',
  'vhr_transaction_currency_code': 'UZS'},


 {'art_other_country_names': None,
  'pk_ba_country_id': 185,
  'sin_active': 1,
  'txt_remarks': '',
  'vhr_common_country_name': 'Uruguay',
  'vhr_formal_country_name': 'Oriental Republic of Uruguay',
  'vhr_nationality': '',
  'vhr_short_country_name': '',
  'vhr_transaction_currency_code': 'UYU'},


 {'art_other_country_names': None,
  'pk_ba_country_id': 184,
  'sin_active': 1,
  'txt_remarks': '',
  'vhr_common_country_name': 'United States',
  'vhr_formal_country_name': 'United States of America',
  'vhr_nationality': '',
  'vhr_short_country_name': '',
  'vhr_transaction_currency_code': 'USD'},

这是我从数据库得到的数据样本如何在单个语句中找到索引?

例如,如果第三个条目的国籍被更新,我需要这样的信息:

arrrSample[index]['vhr_nationality'] ="American"

如何找到索引?我带着'pk_ba_country_id': 184这个值 也就是arrrSample[2]['pk_ba_country_id'] =184

如何在没有循环的情况下从184中找到索引2

我需要从值中找到索引,我不希望使用循环数组,因为数据库可以包含大量数据


Tags: nametxtnoneidnamessincountryactive
1条回答
网友
1楼 · 发布于 2024-09-29 23:24:06

我假设您的目标是这样的(arrrSample的格式不正确)

arrrSample =[{'art_other_country_names': None,'pk_ba_country_id': 186,
  'sin_active': 1,
  'txt_remarks': '',
  'vhr_common_country_name': 'Uzbekistan',
  'vhr_formal_country_name': 'Republic of Uzbekistan',
  'vhr_nationality': '',
  'vhr_short_country_name': '',
  'vhr_transaction_currency_code': 'UZS'},
 {'art_other_country_names': None,
  'pk_ba_country_id': 185,
  'sin_active': 1,
  'txt_remarks': '',
  'vhr_common_country_name': 'Uruguay',
  'vhr_formal_country_name': 'Oriental Republic of Uruguay',
  'vhr_nationality': '',
  'vhr_short_country_name': '',
  'vhr_transaction_currency_code': 'UYU'},
 {'art_other_country_names': None,
  'pk_ba_country_id': 184,
  'sin_active': 1,
  'txt_remarks': '',
  'vhr_common_country_name': 'United States',
  'vhr_formal_country_name': 'United States of America',
  'vhr_nationality': '',
  'vhr_short_country_name': '',
  'vhr_transaction_currency_code': 'USD'}]

for data in arrrSample:
     if data['pk_ba_country_id'] == 184:
        print(data['vhr_common_country_name'])

相关问题 更多 >

    热门问题