find

How can I check if character in a string is a letter? (Python)

How can I check if character in a string is a letter? (Python) Question: I know about islower and isupper, but can you check whether or not that character is a letter? For Example: >>> s = ‘abcdefg’ >>> s2 = ‘123abcd’ >>> s3 = ‘abcDEFG’ >>> s[0].islower() True >>> s2[0].islower() False >>> s3[0].islower() True …

Total answers: 6

Simplest way to get the equivalent of "find ." in python?

Simplest way to get the equivalent of "find ." in python? Question: What is the simplest way to get the full recursive list of files inside a folder with python? I know about os.walk(), but it seems overkill for just getting the unfiltered list of all files. Is it really the only option? Asked By: …

Total answers: 7

Python: Find in list

Python: Find in list Question: I use the following to check if item is in my_list: if item in my_list: print("Desired item is in list") Is "if item in my_list:" the most "pythonic" way of finding an item in a list? EDIT FOR REOPENING: the question has been considered dupplicate, but I’m not entirely convinced: …

Total answers: 14

How to check if a value exists in a dictionary?

How to check if a value exists in a dictionary? Question: I have the following dictionary in python: d = {‘1’: ‘one’, ‘3’: ‘three’, ‘2’: ‘two’, ‘5’: ‘five’, ‘4’: ‘four’} I need a way to find if a value such as “one” or “two” exists in this dictionary. For example, if I wanted to know …

Total answers: 7

Numpy: find first index of value fast

Numpy: find first index of value fast Question: How can I find the index of the first occurrence of a number in a Numpy array? Speed is important to me. I am not interested in the following answers because they scan the whole array and don’t stop when they find the first occurrence: itemindex = …

Total answers: 16

Find and Replace Values in XML using Python

Find and Replace Values in XML using Python Question: I am looking to edit XML files using python. I want to find and replace keywords in the tags. In the past, a co-worker had set up template XML files and used a “find and replace” program to replace these key words. I want to use …

Total answers: 4

Sequence find function?

Sequence find function? Question: How do I find an object in a sequence satisfying a particular criterion? List comprehension and filter go through the entire list. Is the only alternative a handmade loop? mylist = [10, 2, 20, 5, 50] find(mylist, lambda x:x>10) # Returns 20 Asked By: Salil || Source Answers: If you only …

Total answers: 4

Fastest way to search a list in python

Fastest way to search a list in python Question: When you do something like “test” in a where a is a list does python do a sequential search on the list or does it create a hash table representation to optimize the lookup? In the application I need this for I’ll be doing a lot …

Total answers: 4

MATLAB-style find() function in Python

MATLAB-style find() function in Python Question: In MATLAB it is easy to find the indices of values that meet a particular condition: >> a = [1,2,3,1,2,3,1,2,3]; >> find(a > 2) % find the indecies where this condition is true [3, 6, 9] % (MATLAB uses 1-based indexing) >> a(find(a > 2)) % get the values …

Total answers: 9

finding elements by attribute with lxml

finding elements by attribute with lxml Question: I need to parse a xml file to extract some data. I only need some elements with certain attributes, here’s an example of document: <root> <articles> <article type=”news”> <content>some text</content> </article> <article type=”info”> <content>some text</content> </article> <article type=”news”> <content>some text</content> </article> </articles> </root> Here I would like to …

Total answers: 2