Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python | Convert Integral list to tuple list
Next article icon

Python – Convert Float to digit list

Last Updated : 24 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

We are given a floating-point number and our task is to convert it into a list of its individual digits, ignoring the decimal point. For example, if the input is 45.67, the output should be [4, 5, 6, 7].

Using string manipulation

In this method, the number is converted to a string and then each character is checked to see if it is a digit before being added to the result list.

Python
N = 6.456  # Convert Float to digit list using string manipulation s = str(N) res = []  for c in s:     if c.isdigit():         res.append(int(c))  print("List of floating numbers is : " + str(res)) 

Output
List of floating numbers is : [6, 4, 5, 6] 

Explanation: str(N) converts 6.456 into ‘6.456’. The loop iterates through each character in the string and isdigit() filters out the decimal point. Valid digits are converted to integers and appended to res thus resulting in [6, 4, 5, 6].

Let’s discuss some other methods of doing the same task.

Table of Content

  • Using brute force
  • Using list comprehension + isdigit()
  • Using map() + regex expression + findall()
  • Using str() + split() + map() methods

Using brute force

Convert the float to a string and iterate through its characters. Check if each character is a digit and append it as an integer to a list, effectively extracting all numeric digits while ignoring the decimal point.

Python
N = 6.456  # Convert float to digit list x = str(N)  res = [] digs = "0123456789"  for i in x:     if i in digs:         res.append(int(i))  print("List of floating numbers is : " + str(res)) 

Output
List of floating numbers is : [6, 4, 5, 6] 

Explanation: str(N) converts 6.456 to “6.456”. The loop filters out digits using if i in digs, converts them to integers and appends them to res.

Using list comprehension + isdigit()

We can also achieve the same result with the combination of list comprehension and isdigit() funtion. First convert the float to a string and then use list comprehension with isdigit() to filter and extract only numeric characters, converting them into integers. 

Python
N = 6.456  # Convert Float to digit list using  list comprehension + isdigit() res = [int(ele) for ele in str(N) if ele.isdigit()]  print("List of floating numbers is : " + str(res)) 

Output
List of floating numbers is : [6, 4, 5, 6] 

Explanation: str(N) converts 6.456 to “6.456”, then list comprehension iterates through each character, checks if it’s a digit using isdigit() and converts it to an integer.

Using map() + regex expression + findall()

We can extract digits from a floating-point number using regular expressions. First, we convert the number into a string, then use re.findall() with the pattern \\d to find all digit characters. Finally, map(int, …) converts these extracted digits into integers and list() stores them in a list.

Python
import re  N = 6.456  # Convert Float to digit list using map() + regex expression + findall() res = list(map(int, re.findall('\\d', str(N))))  print("List of floating numbers is : " + str(res)) 

Output
List of floating numbers is : [6, 4, 5, 6] 

Explanation: re.findall(‘\\d’, str(N)) scans the string representation of N and extracts all digit characters, returning [‘6’, ‘4’, ‘5’, ‘6’]. map(int, …) converts them into integers, resulting in [6, 4, 5, 6]. The final list is printed as the extracted digits from the float.

Using str() + split() + map() methods

Convert the floating-point number into a list of digits by first converting it into a string and then splitting it at the decimal point using split() method. The integer and decimal parts are concatenated, and map() is used to convert each character back into an integer.

Python
N = 6.456  #Convert Float to digit list x = str(N).split(".") res = list(map(int, x[0]+x[1]))  print("List of floating numbers is : " + str(res)) 

Output
List of floating numbers is : [6, 4, 5, 6] 

Explanation: str(N).split(“.”) splits 6.456 into [‘6’, ‘456’]. The integer and decimal parts are joined and passed to map(int, x[0] + x[1]), converting each digit into an integer. Finally, list() creates the final list [6, 4, 5, 6].



Next Article
Python | Convert Integral list to tuple list
author
manjeet_04
Improve
Article Tags :
  • Python
  • Python Programs
  • Python list-programs
Practice Tags :
  • python

Similar Reads

  • Convert String Float to Float List in Python
    We are given a string float we need to convert that to float of list. For example, s = '1.23 4.56 7.89' we are given a list a we need to convert this to float list so that resultant output should be [1.23, 4.56, 7.89]. Using split() and map()By using split() on a string containing float numbers, we
    3 min read
  • Python | Convert list of tuples into digits
    Given a list of tuples, the task is to convert it into list of all digits which exists in elements of list. Let’s discuss certain ways in which this task is performed. Method #1: Using re The most concise and readable way to convert list of tuple into list of all digits which exists in elements of l
    6 min read
  • Python - List of float to string conversion
    When working with lists of floats in Python, we may often need to convert the elements of the list from float to string format. For example, if we have a list of floating-point numbers like [1.23, 4.56, 7.89], converting them to strings allows us to perform string-specific operations or output them
    3 min read
  • Python | Convert Integral list to tuple list
    Sometimes, while working with data, we can have a problem in which we need to perform type of interconversions of data. There can be a problem in which we may need to convert integral list elements to single element tuples. Let's discuss certain ways in which this task can be performed. Method #1 :
    3 min read
  • Convert Float String List to Float Values-Python
    The task of converting a list of float strings to float values in Python involves changing the elements of the list, which are originally represented as strings, into their corresponding float data type. For example, given a list a = ['87.6', '454.6', '9.34', '23', '12.3'], the goal is to convert ea
    3 min read
  • Convert Floating to Binary - Python
    The task of converting a floating-point number to its binary representation in Python involves representing the number in the IEEE 754 format, which consists of a sign bit, an exponent and a mantissa. For example, given the floating-point number 10.75, its IEEE 754 32-bit binary representation is "0
    3 min read
  • How to Convert Binary Data to Float in Python?
    We are given binary data and we need to convert these binary data into float using Python and print the result. In this article, we will see how to convert binary data to float in Python. Example: Input: b'\x40\x49\x0f\xdb' <class 'bytes'>Output: 3.1415927410125732 <class 'float'>Explana
    2 min read
  • Python | Convert string enclosed list to list
    Given a list enclosed within a string (or quotes), write a Python program to convert the given string to list type. Examples: Input : "[0, 2, 9, 4, 8]" Output : [0, 2, 9, 4, 8] Input : "['x', 'y', 'z']" Output : ['x', 'y', 'z'] Approach #1: Python eval() The eval() method parses the expression passe
    5 min read
  • Python | Convert location coordinates to tuple
    Sometimes, while working with locations, we need a lot of data which has location points in form of latitudes and longitudes. These can be in form of a string and we desire to get tuple versions of same. Let's discuss certain ways in which this task can be performed. Method #1 : Using tuple() + floa
    5 min read
  • Python | Decimal to binary list conversion
    The conversion of a binary list to a decimal number has been dealt in a previous article. This article aims at presenting certain shorthand to do the opposite, i.e binary to decimal conversion. Let's discuss certain ways in which this can be done. Method #1 : Using list comprehension + format() In t
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences