
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
Python - Find the latest valid time that can be obtained by replacing the unknown/hidden digits
When it is required to find the valid time which can be obtained by replacing unknown digits, a method is defined that checks to find the unknown/hidden digit, and then converts it into a different value depending on the value present in the index.
Example
Below is a demonstration of the same
def find_latest_time(my_time): my_time = list(my_time) for i in range(len(my_time)): if my_time[i] == "?": if i == 0: my_time[i] = "2" if my_time[i+1] in "?0123" else "1" elif i == 1: my_time[i] = "3" if my_time[0] == "2" else "9" elif i == 3: my_time[i] = "5" else: my_time[i] = "9" print("".join(my_time)) my_str = '0?:?3' print("The time is :") print(my_str) print("The latest valid time is : ") find_latest_time(my_str)
Output
The time is : 0?:?3 The latest valid time is : 09:53
Explanation
A method named ‘find_latest_time’ is defined that takes a time as a parameter.
It is converted to a list.
It is iterated over and checked to see for the hidden/unknown time values.
If the value of the iterator is 0 or 1 or 3, it is replaced with a specific value.
Outside the method, a string is defined, and is displayed on the console.
The method is called by passing this value.
The output is displayed on the console.
- Related Articles
- Program to find latest valid time by replacing hidden digits in Python
- Maximum possible time that can be formed from four digits in C++
- Find the largest number that can be formed with the given digits in C++
- Find maximum points which can be obtained by deleting elements from array in Python
- Find the difference between the number 738 and that obtained on reversing its digits
- Maximize the given number by replacing a segment of digits with the alternate digits given in C++
- Python Program to find out the number of rooms in which a prize can be hidden
- Program to find nearest time by reusing same digits of given time in python
- Find the difference between the greatest and the least number that can be written using the digits 6,2,7,4,3.
- Indicate collapsible content that can be hidden or shown with Bootstrap
- Maximize the value of A by replacing some of its digits with digits of B in C++
- Name the physical quantity obtained by piding ‘Distance travelled’ by ‘Time taken’ to travel that distance.
- Name the physical quantity obtained by dividing ‘Distance travelled’ by ‘Time taken’ to travel that distance.
- Check if a string can be converted to another string by replacing vowels and consonants in Python
- Find maximum points which can be obtained by deleting elements from array in C++

Advertisements