最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python實(shí)現(xiàn)將列表中各個(gè)值快速賦值給多個(gè)變量

 更新時(shí)間:2020年04月02日 14:12:55   作者:liu2242947853  
這篇文章主要介紹了python實(shí)現(xiàn)將列表中各個(gè)值快速賦值給多個(gè)變量,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

我就廢話(huà)不多說(shuō)啦,還是直接看代碼吧!

list1 = [1,2,3,4]
a,b,c,d = list1

a = 1
b =2

這種方式只有當(dāng)左邊的操作數(shù)個(gè)數(shù)和list1長(zhǎng)度相同時(shí),才可以這么做,不然報(bào)錯(cuò).

我們假設(shè)我們有一個(gè)list對(duì)象List,它的長(zhǎng)度足夠長(zhǎng),想把它從下標(biāo)i開(kāi)始的k個(gè)元素賦給k個(gè)元素,可以這么做:

v1, v2, v3, …, vk = List[i : i + k] #默認(rèn)i=0, k=len(List)

補(bǔ)充知識(shí):python 將某個(gè)字段存儲(chǔ)為列表類(lèi)型

實(shí)現(xiàn)存儲(chǔ)數(shù)據(jù)格式為

{
    "_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實(shí)現(xiàn)將列表中各個(gè)值快速賦值給多個(gè)變量就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • python的slice notation的特殊用法詳解

    python的slice notation的特殊用法詳解

    今天小編就為大家分享一篇python的slice notation的特殊用法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-12-12
  • python錯(cuò)誤SyntaxError:?invalid?syntax的解決方法總結(jié)

    python錯(cuò)誤SyntaxError:?invalid?syntax的解決方法總結(jié)

    SyntaxError: invalid syntax 是Python中常見(jiàn)的錯(cuò)誤類(lèi)型之一,它表示代碼中存在語(yǔ)法錯(cuò)誤,下面這篇文章主要給大家介紹了關(guān)于python錯(cuò)誤SyntaxError:?invalid?syntax的解決方法,需要的朋友可以參考下
    2024-08-08
  • python 將Excel轉(zhuǎn)Word的示例

    python 將Excel轉(zhuǎn)Word的示例

    這篇文章主要介紹了python 將Excel轉(zhuǎn)Word的示例,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-03-03
  • 最新評(píng)論

    岢岚县| 阿巴嘎旗| 时尚| 时尚| 大新县| 新乡市| 陈巴尔虎旗| 科技| 时尚| 项城市| 长兴县| 通州区| 仲巴县| 阳春市| 屯门区| 内黄县| 建始县| 宜良县| 锡林郭勒盟| 岚皋县| 孟津县| 柘荣县| 江安县| 墨玉县| 二连浩特市| 牙克石市| 电白县| 景德镇市| 常德市| 绥宁县| 灵石县| 河津市| 柳江县| 临邑县| 公安县| 富蕴县| 齐河县| 高邮市| 许昌市| 迁西县| 吴忠市|