

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
<p>When it is required to count average digits in a list, a simple iteration, the ‘str’ method and the ‘/’ operator is used.</p><p>Below is a demonstration of the same −</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/3qJa1imi" rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate">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)</pre><h2>Output</h2><pre class="result notranslate">The list is : [324, 5345, 243, 746, 432, 463, 946787] The result is : 3.5714285714285716</pre><h2>Explanation</h2><ul class="list"><li><p>A list is defined and displayed on the console.</p></li><li><p>A variable is initialized to 0.</p></li><li><p>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.</p></li><li><p>The average of these digits is calculated.</p></li><li><p>This result is assigned to a variable.</p></li><li><p>This is the output that is displayed on the console.</p></li></ul>
- Related Questions & Answers
- Find average of a list in python?
- Python - Check if a List contain particular digits
- Extract digits from Tuple list Python
- Program to count number of elements in a list that contains odd number of digits in Python
- Find average of a list in Java
- Python | Sum of number digits in List
- Program to count average of all special values for all permutations of a list of items in Python
- Count digits in a factorial in C++
- Average of each n-length consecutive segment in a Python list
- Python - Check if list contain particular digits
- Convert list of tuples into digits in Python
- Python – Sort a List by Factor count
- Count occurrences of an element in a list in Python
- Count unique sublists within list in Python
- Checking if starting digits are similar in list in Python
Advertisements