在python字典中查找和替换字符串(Find and replace strings in a python dictionary)
我有一个字典,看起来像:
d = {'alleged': ['truths', 'fiels', 'fact', 'infidelity', 'incident'], 'greased': ['axle', 'wheel', 'wheels', 'fields', 'enGine', 'pizza'], 'plowed': ['fields', 'field', 'field', 'incident', '', '']}
我想重新审视并替换一些项目以换取其他字符串。 要查找的字符串和要替换它们的字符串也在字典中,其中键是要查找的字符串,值是要替换它的字符串:
d_find_and_replace = {'wheels':'wheel', 'Field': 'field', 'animals':'plants'}
我尝试使用如下函数:
def replace_all(dic1, dic2): for i, j in dic.items(): dic3 = dic1.replace(i, j) return(dic3)
但它不起作用,因为很明显,它使用替换内置函数
replace
它,并且不可能将它用于字典。 有关如何做到这一点的任何建议? 非常感谢您的帮助。编辑纠正拼写错误。
I have a dictionary that looks like:
d = {'alleged': ['truths', 'fiels', 'fact', 'infidelity', 'incident'], 'greased': ['axle', 'wheel', 'wheels', 'fields', 'enGine', 'pizza'], 'plowed': ['fields', 'field', 'field', 'incident', '', '']}
I would like to go over it and replace some items for another strings. The strings to be find and the ones to replace them are also in a dictionary, in which the key is the string to be found and the value is the string to replace it:
d_find_and_replace = {'wheels':'wheel', 'Field': 'field', 'animals':'plants'}
I tried to use a function like:
def replace_all(dic1, dic2): for i, j in dic.items(): dic3 = dic1.replace(i, j) return(dic3)
but it won't work because obviously, it uses replace built-in function
replace
inside it, and it is not possible to use it for dictionaries. Any suggestions on how to do this? Thank you very much for any help.Edited to correct spelling mistakes.
原文:https://stackoverflow.com/questions/19961432
最满意答案
Android中没有适用于FM收音机的官方API,但是发烧友找到了在Nexus One上启用收音机的方法
到目前为止,我见过的设备具有专有的供应商特定API,可与FM收音机配合使用。
您还可以使用此库为Android开发FM Radio应用程序。 但是这个库依赖于固件。
另一个选择是拥有一个互联网广播应用程序,它从一个在线来源流式传输广播电台。
There is no official API for FM radio in Android, however enthusiasts found the way to enable radio on Nexus One
Devices that I have seen so far have proprietary vendor-specific API to work with FM radio.
You can also use this library to develop a FM Radio App for android. But this library is firmware dependent.
Another options would be to have an internet radio app, which streams the radio station from an online source.
相关问答
更多-
在UWP中它现在是Windows.Devices.Radios ,您可以参考Radio类 ,但FM目前不可用。 您可以参考RadioKind枚举 似乎将来会支持这一点,我想您可以通过Windows反馈工具提交添加此新功能以进行开发的请求。 Yes, it is possible. Make a new project in Visual Studio for Windows Phone 8.0/8.1 Silverlight App after installing the installing the a ...
-
没有办法让2组无线电组具有默认对话框。 您唯一的方法是使用自定义布局创建自定义对话框。 带单选按钮的唯一功能是setSingleChoiceItems,没有别的办法。 setMultipleChoiceItems仅使用复选框,没有组 抱歉 No there is not way to have 2 set of radio groups with default Dialogs. You're only way is to create a custom dialog with a custom layou ...
-
您的手机可以有4种不同的无线电类型,GSM,CDMA,WCDMA和LTE。 但每种无线电类型可以有不同的网络类型。 2G无线电(GSM / CDMA)可以具有以下网络类型: GPRS 边缘 CDMA 1xRTT的 IDEN 3G无线电(WCDMA)可以: UMTS EVD0_0 EVD0_A HSDPA HSUPA HSPA EVDO_B EHRPD HSPAP 4G无线电(LTE)可以具有: LTE 所以,是的,你必须发送无线电类型而不是网络类型,这意味着只有4个可能的值,如Google API文档中所示 ...
-
如何找出android设备是否有蜂窝无线电模块?(How to find out whether android device has cellular radio module?)[2022-09-27]
如果您要在商店中发布,并且希望限制应用程序仅对实际手机可见,则可以在清单中添加,要求提供android.hardware.telephony 。 从文档中查看是否适用于您。 Just in case somebody needs complete solution for this: Reflection is used because some things may not exist on some firmware versions. MainContext - main ... -
如何构建一个不受打瞌睡的Android影响的无线电应用程序?(How to build a radio app without being affected by doze android?)[2021-11-18]
您必须为此创建前台服务。 通常当任何长进程运行时(如下载,播放音乐或视频等),它会在状态栏和锁定屏幕中创建通知。 注意 :您应该只将前台服务用于用户希望系统立即执行或不中断的任务。 这种情况包括将照片上传到社交媒体,或者即使在音乐播放器应用程序不在前台时播放音乐。 您不应该只是为了阻止系统确定您的应用程序处于空闲状态而启动前台服务。 https://developer.android.com/guide/components/services.html#Foreground You have to crea ... -
什么是无线电日志?(What is Radio logs?)[2024-03-26]
它们通常不会被普通用户使用。 无线电与移动网络/ wifi发射器/接收器有关,日志将提供有关它们处于什么状态,连接问题,信号质量等的信息。 They wouldn't usually be used by the average user. The radios are related to the mobile network/wifi transmitters/receivers and the logs will provide information about what state they ar ... -
如果对任何人感兴趣,APEX API $ f_SelectValue可以满足我的需要。 记录在这里 In case it's of interest to anyone the APEX API $f_SelectValue does what I need. Documented here
-
适用于Android的无线电API(A radio API for Android)[2022-12-25]
Android中没有适用于FM收音机的官方API,但是发烧友找到了在Nexus One上启用收音机的方法 到目前为止,我见过的设备具有专有的供应商特定API,可与FM收音机配合使用。 您还可以使用此库为Android开发FM Radio应用程序。 但是这个库依赖于固件。 另一个选择是拥有一个互联网广播应用程序,它从一个在线来源流式传输广播电台。 There is no official API for FM radio in Android, however enthusiasts found the wa ... -
您需要在drawable中创建自定义RadioButton :
如何从Android miui手机访问无线电环境信息(How to access radio environment information from an Android miui phone)[2023-05-19]
RIL基本上是Android框架和Modem之间的接口层。在这里你不能找到有关单元格,相邻单元格等的信息。 Android Framework通过API请求所有信息。 然后,RIL将适当的AT命令发送到调制解调器以获取所请求的信息。 调制解调器的响应由RIL解析,并通过相同的API将信息提供回Android框架。 有关单元/相邻单元的信息,您可以使用以下拨号代码: 拨打*#*#4636#*#*(拨号时请删除空格),弹出一个菜单。 点击电话信息 可以在屏幕上看到有关网络注册,小区ID,相邻小区ID等的信息。 ...相关文章
更多- Python 字符串操作
- Python字符串格式化
- [google面试CTCI] 1-5.替换字符串中特定字符
- Python内建函数(A)
- python字典操作
- python下载pps视频
- Python 列表(list)操作
- pychseg - A Python Chinese Segment Project - Google Project Hosting
- python2和python3的区别
- 探索 Python,第 1 部分: Python 的内置数值类型
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)