Python - Extract digits from Tuple list Last Updated : 07 Nov, 2025 Comments Improve Suggest changes 5 Likes Like Report Given a list of tuples containing numbers of varying lengths, the task is to extract all unique digits present in those tuples.Examples:Input: list = [(15, 3), (3, 9)] Output: [9, 5, 3, 1]Input: list = [(15, 3)] Output: [5, 3, 1] Using List Comprehension + Set Python t = [(15, 3), (3, 9), (1, 10), (99, 2)] temp = ''.join([str(i) for s1 in t for i in s1]) res = [int(i) for i in set(temp)] print(res) Output[1, 5, 2, 3, 9, 0] Explanation:[str(i) for s1 in t for i in s1]: Converts each number in all tuples to a string.' '.join(...): Joins all string numbers into one continuous string.set(temp): Removes duplicate digits.[int(i) for i in set(temp)]: Converts unique string digits back to integers.Using map() + chain.from_iterable() + set() Python from itertools import chain t = [(15, 3), (3, 9), (1, 10), (99, 2)] s = map(str, chain.from_iterable(t)) res = {d for n in s for d in n} print(res) Output{'0', '2', '9', '5', '3', '1'} Explanation:chain.from_iterable(t): Flattens all tuples into a single sequence.map(str, ...): Converts each number to a string.{d for n in s for d in n}: Extracts individual digits and keeps only unique ones.Using RegexA compact method that converts the tuple list to a string, removes unwanted characters using regex, and extracts unique digits using set(). Python import re t = [(15, 3), (3, 9), (1, 10), (99, 2)] s = re.sub(r'[\[\]\(\), ]', '', str(t)) res = [int(i) for i in set(s)] print(res) Output[1, 5, 0, 2, 9, 3] Explanation:str(t): Converts tuple list to string.re.sub(r'[\[\]\(\), ]', '', str(t)): Removes brackets, commas, and spaces.set(s): Collects unique digit characters.int(i) for i in set(s): Converts them back to integers.Using Nested Loops + set()A simple approach that iterates through each tuple, collects all digits as strings, and uses set() to extract unique digits. Python t = [(15, 3), (3, 9), (1, 10), (99, 2)] s = '' for x in t: for y in x: s += str(y) res = list(map(int, set(s))) print(res) Output[5, 1, 2, 3, 0, 9] Explanation:s += str(y): Adds each number as a string.set(s): Removes duplicate digits.map(int, set(s)): Converts unique string digits into integers.Related Articles:list comprehensionregexitertoolsPython | Convert list of tuples into digitsPython - Extract numbers from list of strings Create Quiz Comment M manjeet_04 Follow 5 Improve M manjeet_04 Follow 5 Improve Article Tags : Python Python Programs Python tuple-programs Python List-of-Tuples Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like