# -*- coding: utf-8 -*-
"""Tinesh.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1jMtaUvVW5H86HLF4XUvlgjzOGcX9-d2L
"""
#Program 1 with more arguments
def all_rounder(sequence, method, *args, **kwargs):
"""
Perform a specified method on a given sequence.
Parameters:
- sequence: str, list, tuple, dict
The input sequence on which the method will be performed.
- method: str
The method to be executed on the sequence.
- *args, **kwargs:
Additional arguments and keyword arguments for the specified method.
Returns:
- Modified sequence after performing the specified method.
"""
# Check if the input is a valid sequence type
valid_types = (str, list, tuple, dict)
if not any(isinstance(sequence, t) for t in valid_types):
return "Invalid sequence type"
# Check if the sequence type supports the given method
if not hasattr(sequence, method):
return f"Error: '{method}' method does not exist for {type(sequence).__name__}"
# Perform the specified method on the sequence
getattr(sequence, method)(*args, **kwargs)
return sequence
#Program 1 with 3 arguments
def all_rounder(sequence, method, *args):
"""
Perform a specified method on a given sequence with additional arguments.
Parameters:
- sequence: str, list, tuple, dict
The input sequence on which the method will be performed.
- method: str
The method to be executed on the sequence.
- *args:
Additional arguments for the specified method.
Returns:
- Result of the specified method on the sequence.
"""
# Check if the input is a valid sequence type
valid_types = (str, list, tuple, dict)
if not any(isinstance(sequence, t) for t in valid_types):
return "Invalid sequence type"
# Check if the sequence type supports the given method
if not hasattr(sequence, method):
return f"Error: '{method}' method does not exist for {type(sequence).__name__}"
# Perform the specified method on the sequence with additional arguments
result = getattr(sequence, method)(*args)
return result
#Program 4
import re
def clean_text(text):
# Remove punctuation and convert Spanish characters to English
cleaned_text = re.sub(r'[^\w\s]', '', text)
cleaned_text = cleaned_text.replace('á', 'a').replace('é', 'e').replace('í',
'i').replace('ó', 'o').replace('ú', 'u')
cleaned_text = cleaned_text.replace('Á', 'A').replace('É', 'E').replace('Í',
'I').replace('Ó', 'O').replace('Ú', 'U')
cleaned_text = cleaned_text.replace('ñ', 'n').replace('Ñ', 'N')
return cleaned_text
def is_alphabetical_order(word1, word2, check_ties):
# Check if words are in alphabetical order
min_len = min(len(word1), len(word2))
for i in range(min_len):
if word1[i] < word2[i]:
return True
elif word1[i] > word2[i]:
return False
elif not check_ties:
return False
return len(word1) <= len(word2)
def find_alphabetical_order(fpath, check_ties=True):
result = []
with open(fpath, 'r', encoding='utf-8') as file:
for line in file:
# Split each line into minute and commentary
minute, commentary = line.strip().split('\t ')
# Clean the text
cleaned_commentary = clean_text(commentary)
# Check if words are in alphabetical order
words = cleaned_commentary.split()
if all(is_alphabetical_order(words[i], words[i + 1], check_ties) for i in
range(len(words) - 1)):
result.append(commentary)
return result