Python two-dimensional array of key values generates a turn to JSON

Source: Internet
Author: User

Today, as needed, some of the data crawled by the crawler is sorted into a two-dimensional array, then encoded into a JSON string to pass into the database


So the problem is, in PHP, the process is simple, something like this:


$arr [$key 1][$key 2]= $value


In Python, the string cannot be used as a key value, and I don't know about Python, I didn't find the data, and I found this function:


Dict.setdefault (Key, Default=none)
is similar to get (), but if the key does not exist in the dictionary, the key is added and the value is set to default

As a result, the key value as two parameters passed in, and so on to achieve a similar effect, I hope to help you



Dict.setdefault (Key, Default=none)
is similar to get (), but if the key does not exist in the dictionary, the key is added and the value is set to default

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.