About 9,300,000 results
Open links in new tab
  1. Extracting strings from nested lists in Python - Stack Overflow

    Feb 21, 2012 · Flatten (an irregular) list of lists in Python. I'm trying to use the nltk library in python, and more specifically the wordnet corpus, to extract all the words in a broad semantic category like 'animal'.

  2. Word within a Nested list python - Stack Overflow

    Jun 1, 2018 · If you want to compare all the strings within the nested list (assuming that the sublists only have a depth of 1), you can do a nested for loop. for string in sub_list: if 'boy' in string: print("You got it") You can use a loop to check each element in your list. if 'girl' in each[0]: print("You got it")

  3. python - How to extract elements from a nested list - Stack Overflow

    May 14, 2021 · Suppose the nested list has unknown depth, then we'd have to use recursion def get_elements(l): ret = [] for elem in l: if type(elem) == list: ret.extend(get_elements(elem)) else: ret.append(elem) return ret l = [1,2,[3,4],[[5],[6]]] print(get_elements(l)) # Output: [1, 2, 3, 4, 5, 6]

  4. Python | Extract Nth words in Strings List - GeeksforGeeks

    Mar 18, 2024 · Using the re.findall() function to extract words from each string in the list and then selects the Nth word from each list if it exists. The result is a list containing the Nth words from each string. Step-by-Step Approach. Import the re module. Create a list named test_list containing strings. Print the original list to the console.

  5. Nested List Comprehensions in Python - GeeksforGeeks

    Dec 13, 2023 · Syntax: new_list = [ [expression for item in list] for item in list] Parameters: Python Nested List Comprehensions Examples. Below are some examples of nested list comprehension: Example 1: Creating a Matrix. In this example, we will compare how we can create a matrix when we are creating it with. Without List Comprehension.

  6. Indexing Lists Of Lists In Python - GeeksforGeeks

    Jan 2, 2025 · Iterating over a list of lists is a common task in Python, especially when dealing with datasets or matrices. In this article, we will explore various methods and techniques for efficiently iterating over nested lists, covering both basic and advanced Python concepts.

  7. How to Access Elements in a Nested List in Python - Tutorial Kart

    To access elements in a nested list in Python, you need to use multiple indices. The first index retrieves the inner list, and the second index accesses the specific element within that inner list. In this tutorial, we will explore different ways to access elements in a nested list with examples.

  8. python - How to extract a string contained in nested list ... - Stack ...

    Mar 18, 2021 · use list comprehension to create a new list. good_wrd = [ word for sub_lst in lst for word in sub_lst if "good" in word ] bad_wrd = [ word for sub_lst in lst for word in sub_lst if "bad" in word ]

  9. How to manipulate nested lists quickly | LabEx

    By mastering these Python techniques for nested list manipulation, developers can write more concise, readable, and performant code. The strategies covered in this tutorial demonstrate how to leverage list comprehensions, built-in methods, and efficient algorithms to streamline data processing and transformation tasks with nested lists.

  10. Python Nested List - Learn By Example

    Learn to create a nested list in Python, access change and add nested list items, find nested list length, iterate through a nested list and more.

  11. Some results have been removed