Skip to content

Instantly share code, notes, and snippets.

@Israel0710
Forked from gunar/refactor.py
Last active June 15, 2025 09:48
Show Gist options
  • Select an option

  • Save Israel0710/fb1906766111210bcd0866cb770988dd to your computer and use it in GitHub Desktop.

Select an option

Save Israel0710/fb1906766111210bcd0866cb770988dd to your computer and use it in GitHub Desktop.
from typing import List, Union, Tuple
def is_valid_number(n: Union[int, float]) -> bool:
return isinstance(n, (int, float))
def square_number(n: Union[int, float]) -> Union[int, float]:
return n * n
def process_numbers(data: List[Union[int, float]]) -> Tuple[str, List[Union[int, float]]]:
"""
Processes a list of numbers by squaring each valid number.
Args:
data (List[Union[int, float]]): The input list of numbers.
Returns:
Tuple[str, List[Union[int, float]]]: A tuple containing the status and the list of squared numbers.
"""
if not isinstance(data, list):
return "Error: Input must be a list.", []
if not all(map(is_valid_number, data)):
return "Error: List contains non-numeric values.", []
squared_data = list(map(square_number, data))
return "Success", squared_data
def main():
sample_data = [1, 2, 3, 4.5]
status, result = process_numbers(sample_data)
print(f"Status: {status}")
print(f"Processed Data: {result}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment