Write a Python function ‘Match_num’ which takes a number and a string as argumen
ID: 3698848 • Letter: W
Question
Write a Python function ‘Match_num’ which takes a number and a string as arguments and finds out if the string starts with the specific number. The function should return True if there is a match else returns False.
Write a Python function which takes an IP address as an input argument, removes all leading zeros and returns the IP address
Write a Python function which takes a pattern and a text as input arguments and returns a tuple with the matches
Write a Python function to find the occurrence and prints the position of substrings within a string.
Explanation / Answer
def Match_num(number, string): return str(string).startswith(str(number)) def remove_leading_zeros(ip): string = '' start = True for ch in ip: if ch == '0' and start: string += '' else: start = False string += ch return string def find_matches(pattern, text): matches = [] for i in range(len(text)): if text[i:].startswith(pattern): matches.append(i) return tuple(matches) def print_matches(substring, string): for i in range(len(string)): if string[i:].startswith(substring): print(i, end=' ') print()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.