if I wanted to remove all of the strings within a given list that met a certain criteria, such as having the str'a' in them, how would I go about doing that? the only way that's intuitive to me a for/in loop, but that can't be done. any ideas? Using Python3.2
JoshuaBurleson
23
Posting Whiz
Recommended Answers
Jump to PostThe common idiom is
thelist[:] = (x for x in thelist if not criteria(x)) # for example thelist[:] = (x for x in thelist if not 'a' in x)
Jump to PostPython has some extraordinarily intuitive features I'm noticing, it's almost...English.
List comprehensions as Gribouillis use is a common way to write with python.
>>> l = ['a', 'b', 'c'] >>> a = [x for x in l if not 'a' in x] >>> a ['b', 'c'] >>> …
Jump to PostHere's my view -
def front_x(words):
What does this name mean? I have no idea what this method does - I should be able to tell just by the name. My guess is that it moves the words with "x" at the start of the word to …
All 9 Replies
Gribouillis
1,391
Programming Explorer
Team Colleague
JoshuaBurleson
commented:
Thank you so much!
+1
JoshuaBurleson
23
Posting Whiz
JoshuaBurleson
23
Posting Whiz
JoshuaBurleson
23
Posting Whiz
JoshuaBurleson
23
Posting Whiz
snippsat
661
Master Poster

Enalicho
JoshuaBurleson
23
Posting Whiz

Enalicho
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.