How to create a mask of substrings using np.where or list comprehensions?

I have two python lists of strings that I would like to compare. The first is my main list, containing a series of long codes. The second is a list of partial strings. The desired result is a mask of list 1, populated by the substrings from list two. If no match is found, list3 can return 0, np.nan, ‘-‘, or similar. In other words, I’m looking for the following: With help from folks in another thread, I was able to get close. However, these results return the values in list1, but I would like my result to return the

Python for and if on one line

I have a issue with python. I make a simple list: I want create a “single line code” for find a string. for example, I have this code: But when I watch the variable is wrong (I find the last value of my list): Why does my variable contain the last element and not the element that I want to find? Answer You are producing a filtered list by using a list comprehension. i is still being bound to each and every element of that list, and the last element is still ‘three’, even if it was subsequently filtered out

Python LINQ like methods

As new to Python i really miss LINQ methods. I’ve found this and this questions, which helped me a lot to understand how Python enumerables and generators work. But sill, I want to use good old methods like Select, SelectMany, First, Last, Group, Distinct and so on. I understand, that all cases can be handled by generator and/or for expressions, but it decreases readability of code. Answer Eventually I’ve mock almost all Linq methods and made a proper wrapper, so you can chain methods. It supports any, all, first, first_or_none, last, last_or_none, to_list, to_dictionary, where, distinct, group_by, order_by, take, skip,