python - Python用不同列表中的值替换列表中的空字符串
问题描述
我正在寻找一种巧妙/优雅的方式,可以用" "
其他列表中的值替换一个列表,即:
empty_list = [" ", " ", " "]
other_list = ["a", "b"]
result_list = ["a", "b", " "]
PS我不是在寻找for
循环解决方案
解决方案
new_list = [ a if b == ' ' else b for a,b in zip( other_list, empty_list)]
new_list += empty_list[len(other_list):]
推荐阅读
- swift - 如何从屏幕中间开始在文本字段上进行用户输入?
- javascript - Adm-zip 无效或不受支持的 zip 格式。未找到 END 标头
- c# - 取 n 个元素。如果最后从头开始
- python - 使用 gmail API 解码电子邮件时遇到问题
- git - 当通过烧瓶 API 调用时,gitpython 的 clone_from() 在克隆 repo 时抛出异常
- python - 如何查看 URL 在 python 中返回图像响应?
- sorting - 如何创建按属性值(字符串)排序的方法?
- java - 创建计算器但无法退出
- symfony - Symfony 4 - 安装包的问题
- android - 在 Kotlin 中绘制操纵杆 | 安卓工作室