<jupyter_start><jupyter_text>[Codewars](https://www.codewars.com/kata/54edbc7200b811e956000556/train/python)- Fundamentals- Arrays  Counting Sheep...> >>Consider an array/list of sheep where some sheep may be missing from their place.>> We need a function that counts the number of sheep present in the array (true means present).>> **Examples**>>>`[True,  True,  True,  False,`>>  &nbsp; `True,  True,  True,  True ,`>>  &nbsp; `True,  False, True,  False,`>>  &nbsp; `True,  False, False, True ,`>>  &nbsp; `True,  True,  True,  True ,`>>  &nbsp; `False, False, True,  True]`> >>The correct answer would be 17.>>Hint: Don't forget to check for bad values like null/undefined>><jupyter_code># Tests

array1 = [True,  True,  True,  False,
          True,  True,  True,  True ,
          True,  False, True,  False,
          True,  False, False, True ,
          True,  True,  True,  True ,
          False, False, True,  True ];
              
test.assert_equals(result := count_sheeps(array1), 17, "There are 17 sheeps in total, not %s" % result)<jupyter_output><empty_output><jupyter_text>My Solution My UnderstandingI will be given an array of boolean values. I need to count the number of True values and return sun as an integer.- [x] Count the whole array- [x] Count only the `True` values-------- I didn't want to make a new list and run a For Loop. Figured there was a counting method I could use.-------- Found I could use `sum()` or `[].count(boolean_value)` - I like the `.count()` better-------- [StackOverflow Link - sum() and .count()](https://stackoverflow.com/questions/12765833/counting-the-number-of-true-booleans-in-a-python-list)- [x] Make sure the return statement is correct- [x] Make a case for when the array is empty-------- The `.count()` will return 0 when the array is empty<jupyter_code>def count_sheeps(sheep):

  # # Get the whole length of the array
  # return len(sheep)
  
  # Count only the 'True' values
  return sheep.count(True)
  
  
array1 = [True,  True,  True,  False,
          True,  True,  True,  True ,
          True,  False, True,  False,
          True,  False, False, True ,
          True,  True,  True,  True ,
          False, False, True,  True]

count_sheeps(array1)
array1 = []
count_sheeps(array1)<jupyter_output><empty_output><jupyter_text>Other Solutions<jupyter_code>def count_sheeps(array_of_sheep):
  # TODO May the force be with you
  count = 0
  for sheep in array_of_sheep:
      if sheep:
          count += 1 
  return count
def count_sheeps(a):
    t = 0
    for i in a:
        if i == True:
            t += 1
    return t
def count_sheeps(sheep):
  return len([x for x in sheep if x])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12844378257632166, 'fraction_numerical': 0.01600893521965748, 'mean_word_length': 3.065052950075643, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 40, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '86455', 'license': 'MIT', 'n_tokens_mistral': 918, 'n_tokens_neox': 876, 'n_words': 313, 'path': '2021/September/8_kyu/Monday-Sept-27-Counting-Sheep.ipynb', 'repo_name': 'RMDircio/Coding_Challenges', 'size': '2686'}