Conversion between list of character dictionaries in Python

Source: Internet
Author: User

1 Dictionary Turn characters

Define a dictionary:

Dict = {' name ': ' Python ', ' Age ': 7}
Dictionary-to-character conversions can be cast using str such as:
STR (DICT)


2 Word representable Dictionary:

For example, our data is stored in a dictionary format in a file, but we all read the data type in the file as a character type.

This time, if you want to use a dictionary to manipulate it, it's not going to work. Use the Eval function to convert data to a dictionary type

The output is:

3 Character Turn list

If a string is defined as:

s = ' ad,sad,asdasd,werwer,sdfsdf '

We use the split () method and then reassign the value to a variable #字符串是不可变类型 so we re-assign the value

The new variable is now the list type

Ss=s.split (', ')

Print (Type (ss))

4 List to Characters

If you define a list as:

List1 = [' P ', ' y ', ' t ', ' h ', ' o ', ' n ']

With the Join method, the type of the variable s is the string type.

Conversion between list of character dictionaries in Python

Related Article

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.