Python | Extract Score list of String Last Updated : 09 Apr, 2023 Comments Improve Suggest changes Like Article Like Report Sometimes, while programming we can have a problem in which we dedicate to each character of alphabets a particular score and then according to string, extract only those score for further computations. This can have application in gaming domain. Let's discuss certain ways in which this task can be performed. Method #1 : Using list comprehension + ord() The combination of above functions can be used to perform this task. In this, we perform the task of element iteration using list comprehension and ord() perform the task of checking for index of list that has to be returned. Python3 # Python3 code to demonstrate working of # Extract Score list of String # using list comprehension + ord() # initialize list and string test_list = [3, 4, 5, 7, 5, 8, 1, 5, 7, 10, 6, 7, 9, 11, 3, 1, 3, 6, 7, 9, 7, 4, 6, 4, 2, 1] test_str = "geeksforgeeks" # printing original list and string print("The original list : " + str(test_list)) print("The original string : " + str(test_str)) # Extract Score list of String # using list comprehension + ord() res = [test_list[ord(ele) - 97] for ele in test_str] # printing result print("The Score list is : " + str(res)) Output : The original list : [3, 4, 5, 7, 5, 8, 1, 5, 7, 10, 6, 7, 9, 11, 3, 1, 3, 6, 7, 9, 7, 4, 6, 4, 2, 1] The original string : geeksforgeeks The Score list is : [1, 5, 5, 6, 7, 8, 3, 6, 1, 5, 5, 6, 7] Time Complexity: O(n)Auxiliary Space: O(1) Method #2 : Using zip() + ascii_lowercase + dict() + list comprehension The combination of above functions can also be used to perform this task. In this, the task of joining list element score to character is done by zip() and list comprehension is used to output the final result. Python3 # Python3 code to demonstrate working of # Extract Score list of String # using list comprehension + zip() + ascii_lowercase + dict() import string # initialize list and string test_list = [3, 4, 5, 7, 5, 8, 1, 5, 7, 10, 6, 7, 9, 11, 3, 1, 3, 6, 7, 9, 7, 4, 6, 4, 2, 1] test_str = "geeksforgeeks" # printing original list and string print("The original list : " + str(test_list)) print("The original string : " + str(test_str)) # Extract Score list of String # using list comprehension + zip() + ascii_lowercase + dict() temp = dict(zip(string.ascii_lowercase, test_list)) res = [temp[ele] for ele in test_str] # printing result print("The Score list is : " + str(res)) Output : The original list : [3, 4, 5, 7, 5, 8, 1, 5, 7, 10, 6, 7, 9, 11, 3, 1, 3, 6, 7, 9, 7, 4, 6, 4, 2, 1] The original string : geeksforgeeks The Score list is : [1, 5, 5, 6, 7, 8, 3, 6, 1, 5, 5, 6, 7] Time Complexity: O(n*n), where n is the length of the input list. This is because we’re using zip() + ascii_lowercase + dict() + list comprehension which has a time complexity of O(n*n) in the worst case.Auxiliary Space: O(n), as we’re using additional space res other than the input list itself with the same size of input list. Comment More infoAdvertise with us Next Article Python | Extract Score list of String manjeet_04 Follow Improve Article Tags : Python Python Programs Python list-programs Practice Tags : python Similar Reads Python - Extract Sorted Strings Given a String List, extract all sorted strings. Input : test_list = ["hint", "geeks", "fins", "Gfg"] Output : ['hint', 'fins', 'Gfg'] Explanation : Strings in increasing order of characters are extracted.Input : test_list = ["hint", "geeks", "Gfg"] Output : ['hint', 'Gfg'] Explanation : Strings in 5 min read Python | Extract K sized strings Sometimes, while working with huge amount of data, we can have a problem in which we need to extract just specific sized strings. This kind of problem can occur during validation cases across many domains. Let's discuss certain ways to handle this in Python strings list. Method #1 : Using list compr 5 min read Python - Extract Indices of substring matches Given a String List, and a substring, extract list of indices of Strings, in which that substring occurs. Input : test_list = ["Gfg is good", "for Geeks", "I love Gfg", "Gfg is useful"], K = "Gfg" Output : [0, 2, 3] Explanation : "Gfg" is present in 0th, 2nd and 3rd element as substring. Input : tes 5 min read Python | Extract Nth words in Strings List Sometimes, while working with Python Lists, we can have problems in which we need to perform the task of extracting Nth word of each string in List. This can have applications in the web-development domain. Let's discuss certain ways in which this task can be performed. Method #1: Using list compreh 7 min read Extract Keywords from a List of Strings - Python We are given a list of strings and our task is to extract all words that are valid Python keywords. [Python keywords are reserved words that define the language's syntax (e.g., is, True, global, try).] For example: a = ["Gfg is True", "Its a global win", "try Gfg"] then the output will be: ['is', 'T 3 min read Extract List of Substrings in List of Strings in Python Working with strings is a fundamental aspect of programming, and Python provides a plethora of methods to manipulate and extract substrings efficiently. When dealing with a list of strings, extracting specific substrings can be a common requirement. In this article, we will explore five simple and c 3 min read Python - Extract range sized strings Sometimes, while working with huge amount of data, we can have a problem in which we need to extract just specific range sized strings. This kind of problem can occur during validation cases across many domains. Letâs discuss certain ways to handle this in Python strings list. Method #1 : Using list 4 min read Python Extract Substring Using Regex Python provides a powerful and flexible module called re for working with regular expressions. Regular expressions (regex) are a sequence of characters that define a search pattern, and they can be incredibly useful for extracting substrings from strings. In this article, we'll explore four simple a 2 min read Python | Convert String to list of tuples Sometimes, while working with data, we can have a problem in which we have a string list of data and we need to convert the same to list of records. This kind of problem can come when we deal with a lot of string data. Let's discuss certain ways in which this task can be performed. Method #1: Using 8 min read Python | Extract odd length words in String Sometimes, while working with Python, we can have a problem in which we need to extract certain length words from a string. This can be extraction of odd length words from the string. This can have application in many domains including day-day programming. Lets discuss certain ways in which this tas 5 min read Like