Login

MOVONET

Home Music Blog Group Champion Forum Club

Login | Sign Up| Help

Category:business circle/entertainment circle   Owner python    Members' Amount:11People   Group Status: Public    Create Date:2006-12-31  
     Recently was using django developed the Web project time, discovered python some elementary knowledge grasping was not thorough, because at that time read time also did not have the multi-practices, therefore reorganized the python basic knowledge which some we could use frequently.
must say today is python in sets at function filter.

Python to have in one to construct the filter function, it accepts two parameters: A function and a tabulation,
it returns to a tabulation.
took the first parameter transmits for filter function itself should accept a parameter, this parameter will be in the second parameter tabulation item, the
filter returns tabulation can contain is spread the tabulation parameter to transmit all for filter may by separate letter count returns really (true the element.

python code
  1. >>> def odd(n:
  2. … return n % 2
  3. >>> li = [1, 2, 3, 5, 9, 10, 256, -3]
  4. >>> filter (odd, li
  5. [1, 3, 5, 9, -3]

filter accepts two parameters: A function (odd and a tabulation (li. It transfers the odd function according to the tabulation circulation for each element. If the odd returns is really (remembers, Python reveals all non-zero values for really, then this element is placed in the returns tabulation, is if not so is filtered. The result is one only contains in the original tabulation the odd number tabulation, appears then is in turn same with the original tabulation.

MOKI-COUNT :0 | Views843 | Comments1
  Comments
  • IP :
  • Good useful, thank you!   
  • 2008-12-12 13:13:11

Verification: 7+8=