Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the operations related to Python list list and dictionary dict

Shulou Source: shulou.com Published: 2022-06-01 11:43:08 09月26日 Update

This article mainly explains the "Python list list and dictionary dict related operations", the article explains the content is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Python list list and dictionary dict related operations have" it!

Topic 1 given a list of strings, find the one in which the length of the string is greater than 2 and the first character is the same as the last character, and return the index position. 2 there is a list of two letters pgraine Q, given a number such as n, and then appending 1 to n after the two letters to form a new list. Input: 4, output: ['p1lists,' Q1lists, 'p2lists,' Q2lists, 'p3lists,' Q3lists, 'p4lists,' q4'] 3 combine two lists into a list composed of dictionaries, where the name of the list is k, each value is v, and one-to-one input: color_name = ["Black", "Red", "Maroon", "Yellow"]

Color_code = ["# 000000", "# FF0000", "# 800000", "# FFFF00"]

Output: [{'color_name':' Black', 'color_code':' # 000000'}, {'color_name':' Red', 'color_code':' # FF0000'}, {'color_nam

Answer: 'Maroon',' color_code':'# 800000'}, {'color_name':' Yellow', 'color_code':' # FFFF00'}]

By the way, I deliberately left out the key line in the code of each solution, so you can try to complete it yourself and write it to the comments section.

1def match_words (words):

Ctr = 0

For word in words:

# add this sentence

Ctr + = 1

Return ctr

Print (match_words (['abc',' xyz', 'aba',' 1221']) 2my_list = ['paired,' q']

N = 4

New_list =? # DE8UG hint: consider string concatenation within a certain range

Print (new_list) 3color_name = ["Black", "Red", "Maroon", "Yellow"]

Color_code = ["# 000000", "# FF0000", "# 800000", "# FFFF00"]

Print ([{'color_name': f,' color_code': c} for f, c in?]) # DE8UG hint: zip give it a try?

Thank you for your reading, the above is the content of "what are the operations related to the Python list list and the dictionary dict". After the study of this article, I believe you have a deeper understanding of the operation of the Python list list and the dictionary dict, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Dictionary character two string study content letter prompt solution input output same one-to-one correspondence one line code location key name that is ideas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft macOS NVidia Shulou Information