# Looping over a list - istitle() method

**URL:** <https://discuss.python.org/t/looping-over-a-list-istitle-method/11586>\
**Category:** Python Help\
**Created:** [October 28, 2021, 5:44pm UTC](https://discuss.python.org/t/looping-over-a-list-istitle-method/11586 "2021-10-28T17:44:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![absolutkaffe](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@absolutkaffe](https://discuss.python.org/u/absolutkaffe)\
**Post date:** [October 28, 2021, 5:44pm UTC](https://discuss.python.org/t/looping-over-a-list-istitle-method/11586/1 "2021-10-28T17:44:45Z")

</div>

Hello,

I would like to create a function, checking if every string in a list is in titlecase, returning True if this is the case, False if not

I presume that I would need to loop over the list with a for loop, and then either using an if else statement or a while loop - what would you recommend doing here and is what I am doing here completely off?

eg list  
list1 = [“ABC”, “Abc”, “Abc”]

thanks!

---

<div class="post-metadata">

**Author:** ![BowlOfRed](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bowlofred/32/3379_2.png) [@BowlOfRed](https://discuss.python.org/u/BowlOfRed)\
**Post date:** [October 28, 2021, 6:55pm UTC](https://discuss.python.org/t/looping-over-a-list-istitle-method/11586/2 "2021-10-28T18:55:24Z")

</div>

This is a good place to use a comprehension and all().

```auto
all(x.istitle() for x in list1)

```

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [October 29, 2021, 2:59am UTC](https://discuss.python.org/t/looping-over-a-list-istitle-method/11586/3 "2021-10-29T02:59:26Z")

</div>

I completely agree with BowlOfRed’s suggestion to use all() and a  
comprehension, except I would use a more meaningful variable name, like  
“s” (for string) or “string”, rather than “x” which is normally assumed  
to be some kind of number.

But for learning purposes, we can write this:

```
flag = True
for s in list_of_strings:
    if not s.istitle():
        flag = False
        break # No need to keep scanning.

```

to check each string. If you find a string that is not titlecase, you  
can bail out: it only takes _one_ non-titlecase string for the list to  
not be all titlecase.
