Difference between revisions of "Python:Filtering Tutorial"

From Progzoo
Jump to: navigation, search
(Picking the stans.)
Line 5: Line 5:
 
"filter". Some get through, some don't.
 
"filter". Some get through, some don't.
  
http://www.python.org/doc/2.5.2/lib/string-methods.html includes a list of string methods.
+
https://docs.python.org/2.7/library/string.html includes a list of string methods.
  
  

Revision as of 10:06, 24 May 2014

In these examples we select only some countries to print. A process that takes a list and selects only certain items is a "filter". Some get through, some don't.

https://docs.python.org/2.7/library/string.html includes a list of string methods.


Selecting a region.

Print the countries where the region is Europe.

[Font] [Default] [Show] [Resize] [History] [Profile]

Picking the stans.

Print only those countries where the name ends with stan

[Font] [Default] [Show] [Resize] [History] [Profile]

Countries with a z.

Print only those countries where the name contains the letter z

You can use contains for this.

[Font] [Default] [Show] [Resize] [History] [Profile]

Small countries (by area).

Print the countries that have an area of less than 100.

[Font] [Default] [Show] [Resize] [History] [Profile]