The Python dictionary writes a file join to stitch the list characters into a new string.

Source: Internet
Author: User

A1 = {'Yuan':30000,'Alex':100000,'Egon':50000,'Rain': -} #定义字典f= Open ("Test.txt","w+", encoding="UTF-8") #打开文件 forKeyinchA1: #循环遍历字典 A2=(Key,str (A1[key])) #把字典解析成列表 List1=(List (A2)) #转列表 Print (list1) #打印预览列表 list_str=" ". Join (List1) #join (): An array of connection strings. Generates a new string f.write a string, a tuple, an element in a list, and a specified character (delimiter) (List_str+"\ n") #在写入到文件为了格式好看, you can add a \ n line break once per loop. Print (LIST_STR) #打写预览

# # # #输入结果如下:
[' Egon ', ' 50000 ']
Egon 50000
[' Alex ', ' 100000 ']
Alex 100000
[' Rain ', ' 90 ']
Rain 90
[' Yuan ', ' 30000 ']
Yuan 30000

The Python dictionary writes a file join to stitch the list characters into a new string.

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.