You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从指定字典列表字符串提取所有name字段值并拼接为目标格式字符串

提取字符串中所有name字段的值

输入内容:

[{'self': 'https://jira.zxz.su/rest/api/2/component/11207132',
  'id': '11207',    
  'name': 'SEO'},    
 {'self': 'https://jira.zxz.su/rest/api/2/component/12200123',    
  'id': '12200',    
  'name': 'НКК'}] 

解决方案(Python实现):

利用ast.literal_eval安全解析类Python结构的字符串,再提取目标字段并拼接成指定格式:

import ast

# 待处理的输入字符串
input_str = """[{'self': 'https://jira.zxz.su/rest/api/2/component/11207132',
  'id': '11207',    
  'name': 'SEO'},    
 {'self': 'https://jira.zxz.su/rest/api/2/component/12200123',    
  'id': '12200',    
  'name': 'НКК'}] """

# 解析为Python列表对象
component_list = ast.literal_eval(input_str)

# 提取所有name值并拼接成目标格式
output = "'" + "','".join(item['name'] for item in component_list) + "'"

print(output)

输出结果:

'SEO','НКК'

内容的提问来源于stack exchange,提问作者Dmitri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 11:36:07