Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to count list elements with values in a given range with Python

1 Answer

0 votes
def countValuesInRange(lst, from_, to_):
        count = 0
        size = len(lst)
        for i in range(size):
            if lst[i] >= from_ and lst[i] <= to_:
                count += 1
        return count

       
       
lst = [  3, 6, 0, 17, 9, 1, 8, 7, 4, 10, 18, 11, 20, 30 ]
from_ = 5
to_ = 12
  
print(countValuesInRange(lst, from_, to_))

 
     
'''
run:

6

'''

 



answered Dec 16, 2021 by avibootz

Related questions

...