- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – Average digits count in a List
When it is required to count average digits in a list, a simple iteration, the ‘str’ method and the ‘/’ operator is used.
Below is a demonstration of the same −
my_list = [324, 5345, 243, 746, 432, 463, 946787] print("The list is :") print(my_list) sum_digits = 0 for ele in my_list: sum_digits += len(str(ele)) my_result = sum_digits / len(my_list) print("The result is :") print(my_result)
The list is : [324, 5345, 243, 746, 432, 463, 946787] The result is : 3.5714285714285716
A list is defined and displayed on the console.
A variable is initialized to 0.
The list is iterated over, and the sum of the digits is calculated by first converting the element to a list and determining its length using ‘len’ method.
The average of these digits is calculated.
This result is assigned to a variable.
This is the output that is displayed on the console.
- Find average of a list in python?
- Program to count number of elements in a list that contains odd number of digits in Python
- Program to count average of all special values for all permutations of a list of items in Python
- Python | Sum of number digits in List
- Python - Check if a List contain particular digits
- Extract digits from Tuple list Python
- Average of each n-length consecutive segment in a Python list
- Count digits in a factorial in C++
- Convert list of tuples into digits in Python
- Python – Sort a List by Factor count
- Python - Check if list contain particular digits
- Count occurrences of an element in a list in Python
- Find average of a list in Java
- Count unique sublists within list in Python
- Checking if starting digits are similar in list in Python