- 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 check whether domain and range are forming function or not in Python

Suppose we have a list of data say x, represents a domain and a list of data y (size of y is same as size of x), represents a range. We have to check whether x -> y is a function or not. Here we are considering all elements in x and y are positive.

So, if the input is like x = [1,3,2,6,5] y = [1,9,4,36,25], then the output will be True, because for each x, the corresponding y is its square value here, so this is a function.

To solve this, we will follow these steps −

Here we are considering a simple set of steps. This problem can be solved in some complex way also.

- mp := a new map
- for i in range 0 to size of x, do
- a := x[i]
- b := y[i]
- if a is not in mp, then
- mp[a] := b

- otherwise,
- return False

- return True

## Example

Let us see the following implementation to get better understanding −

def solve(x, y): mp = {} for i in range(len(x)): a = x[i] b = y[i] if a not in mp: mp[a] = b else: return False return True x = [1,3,2,6,5] y = [1,9,4,36,25] print(solve(x, y))

## Input

[1,3,2,6,5], [1,9,4,36,25]

## Output

True

- Related Articles
- Program to check points are forming convex hull or not in Python
- Program to check points are forming concave polygon or not in Python
- Program to check linked list items are forming palindrome or not in Python
- Program to check whether parentheses are balanced or not in Python
- Program to check heap is forming max heap or not in Python
- Program to check whether elements frequencies are even or not in Python
- Program to check whether two sentences are similar or not in Python
- Program to check whether two string arrays are equivalent or not in Python
- Program to check whether different brackets are balanced and well-formed or not in Python
- Program to check whether all leaves are at same level or not in Python
- Program to check whether all palindromic substrings are of odd length or not in Python
- Program to check whether leaves sequences are same of two leaves or not in python
- Program to check whether list is alternating increase and decrease or not in Python
- Program to check whether given graph is bipartite or not in Python
- Program to check whether given password meets criteria or not in Python

Advertisements