提取字典列表中元素的值

2024-01-17

我有一个Python数据结构如下:

A = [{'abc': 'kjkjl'},{'abc': 'hjhjh'},{'abc': '78787'}]

如何从 A 中删除“abc”并创建一个新列表:

B = ['kjkjl','hjhjh','78787']

编辑:使用解决方案我仍然收到以下错误:

return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u03b9' in position 10:             character maps to <undefined>

实际的数据结构如下:

A =

{u'thread': u'Sujet  Topic de la communaut des fans de Star Wars  '}
{u'thread': u'Sujet Topic Unique La Communaut des Fans de Pirates des Caraibes '} {u'thread': u'Sujet Pandora - Topic de la communaut des fans de Avatar et de James Cameron '} {u'thread': u'Sujet Au-del de Brokeback ple-mle'} {u'thread': u'Sujet X Men 4 The Wolvy Gang fanfic'} {u'thread': u'Commentaire sur - Transformers 3'} {u'thread': u'Sujet le Photogramme - saison 2'} {u'thread': u'Sujet Une mditation sur lamour de la beaut'} {u'thread': u'Commentaire sur - Harry Potter et les reliques de la mort - partie 2'} {u'thread': u'Commentaire sur - Inception'} {u'thread': u'ALED - Cin\u03b9ma'} {u'thread': u'Sujet Commentaire sur Twilight - Chapitre 3 hsitation'} {u'thread': u'Sujet Topic unique La Justice league prvu pour 2013'} {u'thread': u'Sujet Commentaire sur Harry Potter et les reliques de la mort - partie 1'} {u'thread': u'Commentaire sur - Harry Potter et les reliques de la mort - partie 1'} {u'thread': u'Sujet Commentaire sur Avatar'} {u'thread': u'Sujet Rebecca and Billy s fan'} {u'thread': u'Sujet ALED - Bistrot'} {u'thread': u'Sujet ALED - Jeux'} {u'thread': u'ALED - Bistrot'} {u'thread': u'Sujet Topic Unique News Transformers III'} {u'thread': u'Sujet Topic Unique News Scream 4 Infos photos BA promo Sans HSFlood '} {u'thread': u'ALED - Jeux'} {u'thread': u'Sujet ALED - Musique'} {u'thread': u'ALED - Musique'} {u'thread': u'Sujet Batmanet une Lgende '} {u'thread': u'Sujet Commentaire sur The Dark Knight Rises'} {u'thread': u'Sujet Commentaire sur Resident Evil Afterlife'} {u'thread': u'Sujet Jake Sully lhomme qui marchait dans sa tte '} {u'thread': u'Sujet De qui Peter Jackson croit-il se moquer'} {u'thread': u'Sujet Commentaire sur Saw 3D'} {u'thread': u'[Topic Unique] News Spider-Man reboot'} {u'thread': u'Sujet Dbat autours sur les news ET rumeurs D'} {u'thread': u'Sujet Commentaire sur Scream 4'} {u'thread': u'Sujet Le Top 100 des internautes'} {u'thread': u'Sujet Topic des news Bilbo le Hobbit prquelle du Seigneur des Anneaux Spoilers possibles'} {u'thread': u'D\u03b9bat autours sur les news ET rumeurs -D'} {u'thread': u'Commentaire sur - The Dark Knight Rises'} {u'thread': u'Sujet Top Cinma 2010'} {u'thread': u'Topic des news Bilbo le Hobbit (pr\u03b9quelle du Seigneur des Anneaux) Spoilers possibles-'} {u'thread': u'Sujet Commentaire sur Pirates des Carabes la Fontaine de Jouvence'} {u'thread': u'Sujet Lunique et vritable explication de matrix revolutions'} {u'thread': u'Sujet Topic DE SECOURS de la communaut des fans de STAR WARS'} {u'thread': u'Sujet Commentaire sur X-Men Le commencement'} {u'thread': u'Commentaire sur - X-Men Le commencement'} {u'thread': u'Sujet TOPIQUE UNIQUE-FORUM OFFICIEL Rumeurs- News-Infos-Photos-BA-Compte rebours de RAMBO V'} {u'thread': u'Sujet Vos citations prfres du Seigneur des Anneaux'} {u'thread': u'Sujet Commentaire sur Piranha 3-D'} {u'thread': u'Sujet Fanarts - vos crations AVATAR'} {u'thread': u'Sujet Commentaire sur Sucker Punch'} {u'thread': u'Commentaire sur - Sucker Punch'} {u'thread': u'Sujet In brightest day in blackest night Green Lantern le film les news c est ici'} {u'thread': u'Sujet Commentaire sur The Expendables'} {u'thread': u'Sujet Commentaire sur Twilight - Chapitre 4 rvlation'} {u'thread': u'Sujet Meeting du TDLCDFDSW pour Juin 2011'} {u'thread': u'Sujet Topic Unique Harry Potter et les Reliques de la Mort Partie II News Photo Bande annonce '} {u'thread': u'Commentaire sur - Twilight - Chapitre 4 - r\u03b9v\u03b9lation'} {u'thread': u'Topic Unique Harry Potter et les Reliques de la Mort (Partie II) [News, Photo, Bande annonce ----]'} {u'thread': u'Sujet Commentaire sur Le Choc des Titans'} {u'thread': u'Sujet Le club des fans de cin'} {u'thread': u'Sujet Commentaire sur Le Dernier matre de lair'} {u'thread': u'Sujet Commentaire sur Black Swan'} {u'thread': u'Commentaire sur - Black Swan'} {u'thread': u"Commentaire sur - Tron l'h\u03b9ritage"} {u'thread': u'Sujet Armada 2008 rassemblement des fans de POTC pour la prise du port de Rouen membres only'} {u'thread': u'Sujet Commentaire sur Tron lhritage'} {u'thread': u'Sujet TOPIC OFFICIEL unique TINTIN news photos scoops '} {u'thread': u'Sujet Commentaire sur Iron Man 2'} {u'thread': u"Top des films de l'ann\u03b9e 2011"} {u'thread': u'Sujet Commentaire sur Prince of Persia les sables du temps'} {u'thread': u'Commentaire sur - Spider-Man (3D)'} {u'thread': u'Commentaire sur - World Invasion - Battle Los Angeles'} {u'thread': u'Sujet Commentaire sur Les Griffes de la nuit'} {u'thread': u'Sujet Commentaire sur World Invasion Battle Los Angeles'} {u'thread': u'Sujet Le merchandising - Les produits drivs'} {u'thread': u'TOPIC OFFICIEL [unique] - TINTIN (news, photos, scoops, ---)'} {u'thread': u'Sujet Commentaire sur Predators'} {u'thread': u'Sujet Box office Tron '} {u'thread': u'Sujet Commentaire sur Tree of Life'} {u'thread': u'Commentaire sur - Tree of Life'} {u'thread': u'Sujet Commentaire sur Robin des Bois'} {u'thread': u'Sujet Commentaire sur Thor'} {u'thread': u'Sujet THOR de Kenneth Brannagh Topic news'} {u'thread': u'Sujet NEW Signalez ici les nouveaux liens Top Ralisateurs et Ralisatrices des internautes rajouter dans le Sticky'} {u'thread': u'Sujet Topic Unique News Breaking Dawn'} {u'thread': u'Sujet Commentaire sur Kick-Ass'} {u'thread': u'Sujet Commentaire sur Le Monde de Narnia Chapitre 3 - LOdysse du Passeur daurore'} {u'thread': u"Commentaire sur - Le Monde de Narnia - Chapitre 3 - L'Odyss\u03b9e du Passeur d'aurore"} {u'thread': u'Sujet Top Cinma 2011'} {u'thread': u'Sujet Commentaire sur Paranormal Activity'} {u'thread': u'Sujet Marc andr Grondin'} {u'thread': u'Sujet Faisons un grand scenario participatif dHP '} {u'thread': u'Sujet Commentaire sur Shutter Island'} {u'thread': u'Commentaire sur - Shutter Island'} {u'thread': u'Sujet Pourquoi ce film est il autant dtest '} {u'thread': u'Sujet Commentaire sur Twilight - Chapitre 2 tentation'} {u'thread': u'Top Cin\u03b9ma 2011'} {u'thread': u'Sujet Commentaire sur Rien dclarer'} {u'thread': u'Sujet Discussion autour des news et rumeur du New Superman Project '} {u'thread': u'Discussion autour des news et rumeur du New Superman Project !'}

>>> B = [a["abc"] for a in A]
>>> B
['kjkjl', 'hjhjh', '78787']
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

提取字典列表中元素的值 的相关文章

  • 使用 pythonbrew 编译 Python 3.2 和 2.7 时出现问题

    我正在尝试使用构建多个版本的 python蟒蛇酿造 http pypi python org pypi pythonbrew 0 7 3 但我遇到了一些测试失败 这是在运行的虚拟机上 Ubuntu 8 04 32 位 当我使用时会发生这种情
  • 使用 psycopg2 在 python 中执行查询时出现“编程错误:语法错误位于或附近”

    我正在运行 Python v 2 7 和 psycopg2 v 2 5 我有一个 postgresql 数据库函数 它将 SQL 查询作为文本字段返回 我使用以下代码来调用该函数并从文本字段中提取查询 cur2 execute SELECT
  • 通过 Scrapy 抓取 Google Analytics

    我一直在尝试使用 Scrapy 从 Google Analytics 获取一些数据 尽管我是一个完全的 Python 新手 但我已经取得了一些进展 我现在可以通过 Scrapy 登录 Google Analytics 但我需要发出 AJAX
  • 通过最小元素比较对 5 个元素进行排序

    我必须在 python 中使用元素之间的最小比较次数来建模对 5 个元素的列表进行排序的执行计划 除此之外 复杂性是无关紧要的 结果是一个对的列表 表示在另一时间对列表进行排序所需的比较 我知道有一种算法可以通过 7 次比较 总是在元素之间
  • Django:按钮链接

    我是一名 Django 新手用户 尝试创建一个按钮 单击该按钮会链接到我网站中的另一个页面 我尝试了一些不同的例子 但似乎没有一个对我有用 举个例子 为什么这不起作用
  • Flask 会话变量

    我正在用 Flask 编写一个小型网络应用程序 当两个用户 在同一网络下 尝试使用应用程序时 我遇到会话变量问题 这是代码 import os from flask import Flask request render template
  • PyUSB 1.0:NotImplementedError:此平台不支持或未实现操作

    我刚刚开始使用 pyusb 基本上我正在玩示例代码here https github com walac pyusb blob master docs tutorial rst 我使用的是 Windows 7 64 位 并从以下地址下载 z
  • SQLALchemy .query:类“Car”的未解析属性引用“query”

    我有一个这里已经提到的问题https youtrack jetbrains com issue PY 44557 https youtrack jetbrains com issue PY 44557 但我还没有找到解决方案 我使用 Pyt
  • Spark KMeans 无法处理大数据吗?

    KMeans 有几个参数training http spark apache org docs latest api python pyspark mllib html highlight kmeans pyspark mllib clus
  • OpenCV 无法从 MacBook Pro iSight 捕获

    几天后 我无法再从 opencv 应用程序内部打开我的 iSight 相机 cap cv2 VideoCapture 0 返回 并且cap isOpened 回报true 然而 cap grab 刚刚返回false 有任何想法吗 示例代码
  • Python 函数可以从作用域之外赋予新属性吗?

    我不知道你可以这样做 def tom print tom s locals locals def dick z print z name z name z guest Harry print z guest z guest print di
  • Python 的“zip”内置函数的 Ruby 等价物是什么?

    Ruby 是否有与 Python 内置函数等效的东西zip功能 如果不是 做同样事情的简洁方法是什么 一些背景信息 当我试图找到一种干净的方法来进行涉及两个数组的检查时 出现了这个问题 如果我有zip 我可以写这样的东西 zip a b a
  • Fabric env.roledefs 未按预期运行

    On the 面料网站 http docs fabfile org en 1 10 usage execution html 给出这个例子 from fabric api import env env roledefs web hosts
  • 将图像分割成多个网格

    我使用下面的代码将图像分割成网格的 20 个相等的部分 import cv2 im cv2 imread apple jpg im cv2 resize im 1000 500 imgwidth im shape 0 imgheight i
  • 有人用过 Dabo 做过中型项目吗? [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 我们正处于一个新的 ERP 风格的客户端 服务器应用程序的开始阶段 该应用程序是作为 Python 富客户端开发的 我们目前正在评估 Dabo
  • Conda SafetyError:文件大小不正确

    使用创建 Conda 环境时conda create n env name python 3 6 我收到以下警告 Preparing transaction done Verifying transaction SafetyError Th
  • 发送用户注册密码,django-allauth

    我在 django 应用程序上使用 django alluth 进行身份验证 注册 我需要创建一个自定义注册表单 其中只有一个字段 电子邮件 密码将在服务器上生成 这是我创建的表格 from django import forms from
  • 从列表指向字典变量

    假设你有一个清单 a 3 4 1 我想用这些信息来指向字典 b 3 4 1 现在 我需要的是一个常规 看到该值后 在 b 的位置内读写一个值 我不喜欢复制变量 我想直接改变变量b的内容 假设b是一个嵌套字典 你可以这样做 reduce di
  • Python 类继承 - 诡异的动作

    我观察到类继承有一个奇怪的效果 对于我正在处理的项目 我正在创建一个类来充当另一个模块的类的包装器 我正在使用第 3 方 aeidon 模块 用于操作字幕文件 但问题可能不太具体 以下是您通常如何使用该模块 project aeidon P
  • 导入错误:没有名为 site 的模块 - mac

    我已经有这个问题几个月了 每次我想获取一个新的 python 包并使用它时 我都会在终端中收到此错误 ImportError No module named site 我不知道为什么会出现这个错误 实际上 我无法使用任何新软件包 因为每次我

随机推荐