1

What is the most pythonic way to filter the list from the number?

 2 years ago
source link: https://www.codesd.com/item/what-is-the-most-pythonic-way-to-filter-the-list-from-the-number.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

What is the most pythonic way to filter the list from the number?

advertisements

i have this :

['SPRD', '60', 'p25']

I want to generate that :

['SPRD', 'p']

What is the most pythonic way to do that?

Thanks.


In [25]: l = ['SPRD', '60', 'p25']

In [26]: filter(None,(s.translate(None,'1234567890') for s in l))
Out[26]: ['SPRD', 'p']

Related Articles

The most effective way to filter a list that contains (almost) duplicates in .Net

I have a .Net backend that allows me to query items via the corresponding Client API by their .Id and .Revision property and even better, in bulk by providing a List of these combos. However, each .Id may only appear once per query but the input does

The most pythonic way to get a range from the length of a list?

I'm trying to get some slices from some tuples, that look like this: classes = ('1 hrs A', '2 hrs A', '3 hrs A', '3 hrs B', '3 hrs C', '3 hrs C', '3 hrs C') What I have done is: for i in range(len(classes)): print(classes[i][0]) Which produces the de

The most pythonic way of writing a function to pass arguments or a tuple of arguments

What is a most pythonic way to write a function to either pass in arguments or a tuple/list of arguments? For example, a function add could either take in an argument of add(1, 2) or add((1, 2)) and both output 3. What I have so far: (it works, but d

What is the most pythonic way to avoid specifying the same value in a string

message = "hello %s , how are you %s, welcome %s"%("john","john","john") What is the most pythonic way to avoid specifying "john" 3 times and instead to specify one phrase. "hello %(name)s , how are y

The most pythonic way to provide global configuration variables in config.py?

In my endless quest in over-complicating simple stuff, I am researching the most 'Pythonic' way to provide global configuration variables inside the typical 'config.py' found in Python egg packages. The traditional way (aah, good ol' #define!) is as

The most pythonic way of listing a broken table?

I have something like this: for i, item in enumerate(weapons): print "%s : %s" % (i, item) print "#####" for i, item in enumerate(weapons): if item is not 'bananas': print "%s : %s"%(i, item) And I get this: 0: apples 1: bana

How to make a list of n mixed lists in order (in the most pythonic way possible)?

This question already has an answer here: Pythonic way to combine two lists in an alternating fashion? 16 answers Having this: a = 12 b = [1, 2, 3] What is the most pythonic way to convert it into this?: [12, 1, 12, 2, 12, 3] try this: >>> a 12 &

The most pythonic way to manage the division of a class into several classes

I have a class that can interface with either Oracle or MySQL. The class is initialized with a keyword of either "Oracle" or "MySQL" and a few other parameters that are standard for both database types (what to print, whether or not to

The most pythonic way to check the string contains a substring that is also present in the list

I have string , str='http://facebook.com/something/something/1.php' And have list , l= ['facebook','twitter'] I want to check that the str has atleast any of the keyword from the list. What is the most pythonic way to acheive this? What I have tried

The most pythonic way of grouping an iterator in blocks of size n

Possible Duplicate: How do you split a list into evenly sized chunks in Python? If you have an iterator iter with values i0, i1, i2, ..., what's the most Pythonic way to get an iterator whose values are [i0, i1, i2], [i3, i4, i5], ... The above would

The most efficient way to divide a list into equal size subcategories using jquery

Using jQuery, what's the most efficient way to split a list <ul class="columnar"><li></li>... <li></li></ul> into several sublists <ul class="column1"><li></li>... <li></li

What is a good pythonic way to find duplicate objects?

I frequently use sorted and groupby to find duplicates items in an iterable. Now I see it is unreliable: from itertools import groupby data = 3 * ('x ', (1,), u'x') duplicates = [k for k, g in groupby(sorted(data)) if len(list(g)) > 1] print duplicat

the most idiomatic way to implement recursive list comprehension in F #

the question in short: What is the most idiomatic way to do "recursive List comprehension" in F#? more detailed: As I have learned so far (I am new to F#) we have essentially the following tools to "build up" lists: List.map and list c

The most effective way to compare two List & lt; T & gt;

I'm trying to compare two lists. Here's the extension method I'm trying to use: public static bool EqualsAll<T>(this IList<T> a, IList<T> b) { if (a == null || b == null) return (a == null && b == null); if (a.Count != b.Count) r

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK