python实现将列表中各个值快速赋值给多个变量
2020-04-03 12:04
1756 查看
我就废话不多说啦,还是直接看代码吧!
list1 = [1,2,3,4]
a,b,c,d = list1
则
a = 1
b =2
等
这种方式只有当左边的操作数个数和list1长度相同时,才可以这么做,不然报错.
我们假设我们有一个list对象List,它的长度足够长,想把它从下标i开始的k个元素赋给k个元素,可以这么做:
v1, v2, v3, …, vk = List[i : i + k] #默认i=0, k=len(List)
补充知识:python 将某个字段存储为列表类型
实现存储数据格式为
{ "_index": "nested-20180815", "_type": "stb-iptv-montor-m-gather-apk", "_id": "AWU8sZboGQQbsn0rAW4J", "_score": 1, "_source": { "mdiNested": [ { "mdiMLR": 0, "mdiType": "0" }, { "mdiMLR": 0, "mdiType": "1" }, { "mdiMLR": 0, "mdiType": "2" }, { "mdiMLR": 0, "mdiType": "3" }, { "mdiMLR": 0, "mdiType": "4" }, { "mdiMLR": 0, "mdiType": "5" } ] } }
代码:
from elasticsearch import Elasticsearch from elasticsearch import helpers import json es_20 = Elasticsearch(hosts="1.0.0.0", port=9200, timeout=15000) time_ = "20180815" index_20 = "nested-{0}".format(time_) type_20 = "stb-iptv-montor-m-gather-apk" def set_mapping(): my_mappping = { type_20: { "properties": { "mdiNested": { "properties": { "mdiMLR": { "type": "short" }, "mdiType": { "type": "keyword" } } } } } } create_index = es_20.indices.create(index=index_20, body=None) create_mapping = es_20.indices.put_mapping(index=index_20, body=my_mappping, doc_type=type_20) mdiMLR = [0,1,2,3,4] mdiType = ["0","1","2","3","4","5"] actions = [] dict_ ={} for mdiMLR_ in mdiMLR: dict_list = [] for type in mdiType: t1 ={'mdiMLR': mdiMLR_, 'mdiType': type} dict_list.append(t1) action = { "_index": index_20, "_type": type_20, "_source": { "mdiNested": dict_list } } actions.append(action) helpers.bulk(es_20, actions)
以上这篇python实现将列表中各个值快速赋值给多个变量就是小编分享给大家的全部内容了,希望能给大家一个参考
您可能感兴趣的文章:
相关文章推荐
- python中将列表中各个值快速赋值给多个变量
- python初学者快速入门(二)操作符、变量和赋值
- python用列表实现多重赋值
- Python 核心编程笔记_Chapter_2 Note_3_赋值与变量_字符串_列表list_元组tuple_字典dict
- Python中实现变量赋值传递时的引用和拷贝方法
- python实现同时给多个变量赋值的方法
- python实现同时给多个变量赋值的方法
- python实现同时给多个变量赋值的方法
- 玩蛇记之用python实现易宝快速支付接口
- python 多变量赋值
- Python 最近因开发项目的需要,有一个需求,就是很多SNS网站都有的通过 Email地址 导入好友列表,不过这次要导入的不是Email 列表,而是QQ的好友列表。 实现方式: 通过goog
- Python 小程序,实现比较两个列表范围
- Python中无限元素列表的实现方法
- C/C++ 通过初始化列表和构造函数内赋值初始化成员变量的区别
- Python实现txt文件内容快速合并功能
- python 3.2 实现快速排序 源代码
- python变量赋值(可变与不可变) 分类: python基础学习 python Module 2013-10-30 11:59 1036人阅读 评论(0) 收藏
- python数据结构与算法 19有序列表 ADT及实现
- Python中变量赋值使用、特殊字符和注释等的特点
- Python 快速排序 堆排序——Python实现一些算法持续更新