{"id":12675,"date":"2021-09-30T16:30:23","date_gmt":"2021-09-30T11:00:23","guid":{"rendered":"https:\/\/python-programs.com\/?p=12675"},"modified":"2021-11-22T18:33:35","modified_gmt":"2021-11-22T13:03:35","slug":"python-program-to-print-all-perfect-squares-from-a-list-using-list-comprehension-and-math-module","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-all-perfect-squares-from-a-list-using-list-comprehension-and-math-module\/","title":{"rendered":"Python Program to Print all Perfect Squares from a List using List Comprehension and Math Module"},"content":{"rendered":"

Given a list, the task is to write a program to print all perfect squares from the given list using list comprehension and Math Module.<\/p>\n

Using list comprehension and the math module, you’ll learn how to check whether the elements in a Python list entered by the user are perfect squares or not.<\/p>\n

List comprehensions are a neat trick that allows us to create a new list depending on the values of an existing list in only one line, making the code look shorter and more concise because we aren’t committing to the problem with an entire loop.
\nPython’s math module is a highly valuable tool because it offers a large number of mathematical functions that we may utilize in our programs.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list =[19, 24, 25, 36, 81, 144, 600, 900, 225, 4, 9, 1, 16, 49, 23, 49, 25, 10, 25]<\/pre>\n

Output:<\/strong><\/p>\n

The given list is = [19, 24, 25, 36, 81, 144, 600, 900, 225, 4, 9, 1, 16, 49, 23, 49, 25, 10, 25]\r\nThe perfect squares numbers of the given list is = [25, 36, 81, 144, 900, 225, 4, 9, 1, 16, 49, 49, 25, 25]<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list =[37, 82, 81, 467, 839, 8383, 1000, 1900, 10000, 9, 48, 49, 64, 121, 56]<\/pre>\n

Output:<\/strong><\/p>\n

Enter some random List Elements separated by spaces = 37 82 81 467 839 8383 1000 1900 10000 9 48 49 64 121 56\r\nThe given list is = [37, 82, 81, 467, 839, 8383, 1000, 1900, 10000, 9, 48, 49, 64, 121, 56]\r\nThe perfect squares numbers of the given list is = [81, 10000, 9, 49, 64, 121]<\/pre>\n

Python Program to Print all Perfect Squares from a List using List Comprehension and Math Module<\/h2>\n

Below are the ways to print all perfect squares from the given list using list comprehension and Math Module.<\/p>\n