[Tutor] A very simple question - just for fun

Gregor Lingl glingl@aon.at
Fri, 31 May 2002 17:17:41 +0200


Just for fun another way to do the same:

MyList = ["abc", "def", "ghi"]
YourList = ["abc", "Def", "ghi"]

# anotherCheckIfOnlyLower, shortly CIOL
def CIOL(lst):
    return lst==[] or lst[0].islower() and CIOL(lst[1:])

# ------------------ Shell:

>>> MyList = ["abc", "def", "ghi"]
>>> YourList = ["abc", "Def", "ghi"]
>>> CIOL(MyList)
1
>>> CIOL(YourList)
0
>>>

Have fun!
Gregor


Nicole Seitz schrieb:

> Hi there!
>
> I'd like to write a function that gets a list , checks if there are only
> strings in the list starting with a lowercase letter and then returns 1 if
> only lowercase, 0 if not.
> How can I do that?
>
> example list:
>
> myList = [ "abc", "def", "Cde"]
>
> If I write:
>
> def checkIfOnlyLower(list):
>      for item in list:
>           if item[0].islower():
>              return 1
>          else:
>             return 0
>
> the function will return 1 as soon as it comes to the first string starting
> with a lowercase letter.But that's not what I want.
>
> Hope you can help me.
>
> Thanks in advance.
>
> Nicole
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor