
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Program to count number of elements in a list that contains odd number of digits in Python
Suppose we have a list of positive numbers called nums, we have to find the number of elements that have odd number of digits.
So, if the input is like [1, 300, 12, 10, 3, 51236, 1245], then the output will be 4
To solve this, we will follow these steps −
- c:= 0
- for i in range 0 to size of nums, do
- s:= digit count of nums[i]
- if s is odd, then
- c:= c+1
- return c
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, nums): c=0 for i in range(len(nums)): s=len(str(nums[i])) if s%2!=0: c=c+1 return c ob = Solution() print(ob.solve([1, 300, 12, 10, 3, 51236, 1245]))
Input
[1, 300, 12, 10, 3, 51236, 1245]
Output
4
- Related Articles
- Golang Program to Count the Number of Digits in a Number
- Write a program in Python to count the number of digits in a given number N
- Program to count number of stepping numbers of n digits in python
- Program to count number of valid pairs from a list of numbers, where pair sum is odd in Python
- Find count of digits in a number that divide the number in C++
- Python Program to Find Element Occurring Odd Number of Times in a List
- Python | Sum of number digits in List
- Count odd and even digits in a number in PL/SQL
- Program to find nearest number of n where all digits are odd in python
- Java Program to Count Number of Digits in an Integer
- Swift Program to Count Number of Digits in an Integer
- Haskell Program to Count Number of Digits in an Integer
- Kotlin Program to Count Number of Digits in an Integer
- Program to count number of elements present in a set of elements with recursive indexing in Python
- Java program to Count the number of digits in a given integer

Advertisements