Using a list comprehension

line = '0,1,2,3,4,5,6,7,8,9,10'
lst = line.split(',')
one, four, ten = [lst[i] for i in [1,4,10]]
Answer from has2k1 on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-get-specific-elements-from-list-in-python
How to get specific elements from list in python - GeeksforGeeks
July 23, 2025 - In this article, we will learn how to get specific item(s) from given list. There are multiple methods to achieve this. Most simple method is accessing list item by Index. ... a = [1, 'geeks', 3, 'for', 5] # accessing specific list item with ...
🌐
Finxter
blog.finxter.com › home › learn python blog › how to get specific elements from a list? – most pythonic way!
How to Get Specific Elements From a List? - Most Pythonic Way! - Be on the Right Side of Change
July 2, 2020 - For example, we could want to get all elements from the list ps that have a distance of 6.0 or more from (0, 0). Since we don’t know the indices of those elements, we can’t use a solution that requires the indices. Python provides a built-in function called filter().
Discussions

How to get specific values from an element of the list
You can't ever do for i[0]..., that makes no sense. But you don't need a loop here at all. Use index or find to locate the position of "on" in the string, then slice from there: heading = headings[0] pos = heading.find("on") if pos != -1: result = heading[pos+3:] More on reddit.com
🌐 r/learnpython
7
1
December 24, 2021
How to access List elements in Python - Stack Overflow
I have a list: list = [['vegas','London'], ['US','UK']] How to access each element of this list? More on stackoverflow.com
🌐 stackoverflow.com
How can I get a value at any position of a list
I have a numbers added in the list, and want to get a value at a particular number from the list. I tried one = (open(input("Open list: ")).read().splitlines()) list = one print(list) for i in range(len(list)): print(list.index(i)) And I’m getting error ['12026898019', '12024759878', ... More on discuss.python.org
🌐 discuss.python.org
6
0
October 1, 2022
[Python] Elementtree - how to select certain attribute from one selected root.
The simplest route would probably be to use the XPath support . Example: import xml.etree.ElementTree as ET root = ET.fromstring(xml_text) print(root.find("item[@name='Mace']/attribute[@mindmg]").get('mindmg')) The XPath query "item[@name='Mace']/attribute[@mindmg]" means find an attribute element that has a mindmg attribute, and which is a child of an item element that has a name attribute with value 'Mace'. That will return an Element object, which has a get method for retrieving the attribute value. Side note, it's very strange to have elements named attribute. That's technically fine, but usually when you say attribute you mean attribute, i.e. More on reddit.com
🌐 r/learnprogramming
4
7
November 25, 2013
🌐
GeeksforGeeks
geeksforgeeks.org › python › extract-elements-from-a-python-list
Extract Elements from a Python List - GeeksforGeeks
July 23, 2025 - z = [10, 20, 30, 40, 50] # Using list comprehension to filter elements from a list f = [item for item in z if item > 25] print(f) ... enumerate() function is useful when we want both the index and the value of each element in a list.
🌐
Reddit
reddit.com › r/learnpython › how to get specific values from an element of the list
r/learnpython on Reddit: How to get specific values from an element of the list
December 24, 2021 -

Hello everyone!

I have a document in Word that I've already parsed.

Here's how headings of that document look like in the list:

['Client Acceptance Screening Report on LTD Western Stream','Analysis of actual or alleged integrity issues','International blacklists, sanctions or other geopolitical concerns','Politically Exposed Persons (PEP)','Corporate details']

How can I get everything from the first element of the list after the word 'on'. I need to get the name of the legal entity which is LTD 'Western Stream'.

I tried this:

scanning = False
    for i[0] in heading:
        if i == 'o' and i+1 == 'n':
        scanning = True
        continue
    if scanning == True:
        print(i)

But it doesn't work.

I also tried this, but it doesn't work either:

scanning = False
for i[0] in heading:
    i[0] = q
    if q == 'o' and q == 'n':
        scanning = True
        continue
    if scanning == True:
        print(q)

I would be very grateful for the help.

🌐
Quora
quora.com › How-do-I-get-a-specific-item-from-a-list-in-Python
How to get a specific item from a list in Python - Quora
We can get the first value in a Python list by calling the index position of that list. ... Here, the first value, 'Apple', of the list is called by its index position, ‘trees[0]’. ... You can use slicing concepts of python when you want to access specific elements from the list.
Find elsewhere
🌐
YouTube
youtube.com › shorts › EaWKY7wApgc
How To Get Specific Elements From A List In Python - YouTube
In this python tutorial, I show you how to get specific elements from a list in python! I show you two methods you can use to get specific elements from a li...
Published   November 15, 2024
🌐
AskPython
askpython.com › home › 5 easy ways to extract elements from a python list
5 Easy Ways To Extract Elements From A Python List - AskPython
December 29, 2021 - The print statement prints the ... filled the elements into the list. Then we used ‘varx’ variable to specify the enumerate function to search for ‘1,2,5’ index positions....
🌐
GeeksforGeeks
geeksforgeeks.org › python-get-elements-till-particular-element-in-list
Python | Get elements till particular element in list | GeeksforGeeks
April 6, 2023 - The auxiliary space complexity of the code is O(n), as a new list is created with the elements up to the index of N using list slicing. Method #2 : Using generator This task can also be performed using the generator function which uses yield to get the elements just till the required element and breaks the yields after that element. ... # Python3 code to demonstrate working of # Get elements till particular element in list # using generator # helper function to perform task def print_ele(test_list, val): for ele in test_list: if ele == val: return yield ele # initialize list test_list = [1, 4,
🌐
Python Guides
pythonguides.com › python-select-from-a-list
How to Select Items From a List in Python
January 27, 2026 - If you need just one random item, use random.choice(). If you need a specific number of unique items, use random.sample(). When I am working with lists of tuples or dictionaries, the operator module’s itemgetter can be a lifesaver. from operator import itemgetter # List of US Presidential Election Years and Winners (Example) elections = [ (2020, "Biden"), (2016, "Trump"), (2012, "Obama"), (2008, "Obama") ] # Selecting just the names of the winners # This grabs the item at index 1 for every tuple in the list get_names = itemgetter(1) winners = [get_names(e) for e in elections] print("List of Winners:", winners)
🌐
Linux Hint
linuxhint.com › python_find_element_list
Linux Hint – Linux Hint
Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-first-and-last-elements-of-a-list
Get first and last elements of a list in Python - GeeksforGeeks
Explanation:[a[i] for i in (0, -1)] create a new list by accessing a[0] (first element 1) and a[-1] (last element 4), resulting in [1, 4], which is stored in res. itemgetter() function from the operator module fetches elements by index.
Published   July 11, 2025
🌐
LabEx
labex.io › tutorials › python-how-to-access-a-specific-element-in-a-python-list-397938
How to access a specific element in a Python list | LabEx
Understanding the basics of Python lists is a fundamental step in mastering the language and becoming a proficient Python programmer. The most common way to access elements in a Python list is by using indexing.
🌐
IronPDF
ironpdf.com › ironpdf blog › pdf tools › python-find-in-lists
Python Finding Elements in Lists (Beginner-Friendly Guide)
April 24, 2026 - You can use it in combination with a conditional expression to filter out elements based on a specified criterion. my_list = [1, 2, 3, 4, 5] # Find all even numbers in the list using linear search even_numbers = [x for x in my_list if x % 2 == 0] print("Even numbers:", even_numbers) ... List comprehension can also be used to find duplicates, as demonstrated below. from collections import Counter def find_duplicates_counter(lst): counter = Counter(lst) # Return a list of items that appear more than once return [item for item, count in counter.items() if count > 1] # Example usage: my_list = [1, 2, 3, 4, 2, 5, 6, 1, 7, 8, 9, 1] # Print the duplicate elements using Counter print("Duplicate elements using Counter:", find_duplicates_counter(my_list))
🌐
Python.org
discuss.python.org › python help
How can I get a value at any position of a list - Python Help - Discussions on Python.org
October 1, 2022 - I have a numbers added in the list, and want to get a value at a particular number from the list. I tried one = (open(input("Open list: ")).read().splitlines()) list = one print(list) for i in range(len(list)): …
🌐
Programiz
programiz.com › python-programming › methods › list › index
Python List index()
In this tutorial, we will learn about the Python List index() method with the help of examples.
🌐
freeCodeCamp
freecodecamp.org › news › python-find-in-list-how-to-find-the-index-of-an-item-or-element-in-a-list
Python Find in List – How to Find the Index of an Item or Element in a List
February 24, 2022 - You can give a value and find its index and in that way check the position it has within the list. For that, Python's built-in index() method is used as a search tool. ... .index() is the search method which takes three parameters.
🌐
W3Schools
w3schools.com › python › gloss_python_access_list_items.asp
Python Access List Items
Specify negative indexes if you want to start the search from the end of the list: This example returns the items from index -4 (included) to index -1 (excluded) thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(thislist[-4:-1]) Try it Yourself » · Python Lists Tutorial Lists Change List Item Loop List Items List Comprehension Check If List Item Exists List Length Add List Items Remove List Items Copy a List Join Two Lists