Last active
October 25, 2015 19:17
-
-
Save huseyin/3d77946c9f21d9127f2c to your computer and use it in GitHub Desktop.
Python list comprehension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Cümle içerisindeki kelimelerin uzunluklarını döndür | |
def wordsize(string): | |
""" wordsize(string) | |
""" | |
return [len(word) for word in string.split()] | |
# Ufak bir test aracı | |
def unittest(str, expr): | |
""" unittest(str, expr->expression) | |
""" | |
if wordsize(str) == expr: | |
return True | |
else: | |
return False | |
if __name__ == '__main__': | |
str = "foo bar baz" | |
print unittest(str, [3, 3, 3]) | |
print unittest(str, [2, 4, 1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Şöyle de olabilir miydi ?
Neden olmasın ki? Olur olur.
lambda
daha şık olur hem de 😊 👍