In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to convert the Python string type list into a real list type". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to convert a Python string type list into a real list type.
In the process of writing code, we often use the for loop to loop the list, so if we get a list of type str and for it, we will see the following code and figure:
Str_list = str (['axiajiajiajiaoyun']) for row in str_list: print (row)
Results:
So the for loop prints out each character of the str type list one by one, and this result is not what we want, so how to solve this problem? To use the third-party module, look at the following code
From ast import literal_eval# assumes that you get a list of str types str_list = str (['axiaxiajiaozhuo']) print (type (str_list)) # # through the function literal_eval Convert a list of type str to a real list type of type list new_list = literal_eval (str_list) print (type (new_list)) # # and then you can get every value in the list for row in new_list: print (row) # execution result''abc''' through the for loop
The literal function of ast will determine whether the content to be calculated is a legal python type after calculation. If so, the operation will be performed, otherwise the operation will not be performed.
At this point, I believe you have a deeper understanding of "how to convert a Python string type list into a real list type". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.