回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我怎样才能只提取值</p>
<p>我有以下代码:</p>
<pre><code>data = []
with open('city.txt') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
data.append(row[3])
</code></pre>
<p>在列表后面附加以下内容(列表非常庞大):</p>
<p>[…….“‘id’:‘AX~仅限~Mariehamn’,‘id’:‘AX~仅限~salvik’,‘id’:‘AX~仅限~Sund’”</p>
<p>我如何才能将键“id”的值附加到列表中</p>
<p>我只想把它附加到列表中:<code>AX~only~Saltvik</code>,依此类推</p>
<p>city.txt是包含以下内容的文件(90k行文件):</p>
<pre><code>{'name': 'Herat', 'displayName': 'Herat', 'meta': {'type': 'CITY'}, 'id': 'AF~HER~Herat', 'countryId': 'AF', 'countryName': 'AF', 'regionId': 'AF~HER', 'regionName': 'HER', 'latitude': 34.3482, 'longitude': 62.1997, 'links': {'self': {'path': '/api/netim/v1/cities/AF~HER~Herat'}}}
{'name': 'Kabul', 'displayName': 'Kabul', 'meta': {'type': 'CITY'}, 'id': 'AF~KAB~Kabul', 'countryId': 'AF', 'countryName': 'AF', 'regionId': 'AF~KAB', 'regionName': 'KAB', 'latitude': 34.5167, 'longitude': 69.1833, 'links': {'self': {'path': '/api/netim/v1/cities/AF~KAB~Kabul'}}}
so on ....
</code></pre>
<p>当我在for循环语句中打印(行)时,我得到以下结果(这只是输出的最后一行):</p>
<pre><code>["{'name': 'Advancetown'", " 'displayName': 'Advancetown'", " 'meta': {'type': 'CITY'}", " 'id': 'AU~QLD~Advancetown'", " 'countryId': 'AU'", " 'countryName': 'AU'", " 'regionId': 'AU~QLD'", " 'regionName': 'QLD'^C: 152.7713", " 'links': {'self': {'path': '/api/netim/v1/cities/AU~QLD~Basin%20Pocket'}}}"]
</code></pre>