나는 이렇게 학습한다/Algorithm & SQL

0127. Remove the time

daco2020 2023. 1. 28. 17:23
반응형

You're re-designing a blog and the blog's posts have the following format for showing the date and time a post was made:

Weekday Month Day, time e.g., Friday May 2, 7pm

You're running out of screen real estate, and on some pages you want to display a shorter format, Weekday Month Day that omits the time.

Write a function, shortenToDate, that takes the Website date/time in its original string format, and returns the shortened format.

Assume shortenToDate's input will always be a string, e.g. "Friday May 2, 7pm". Assume shortenToDate's output will be the shortened string, e.g., "Friday May 2".



Solution:

def shorten_to_date(long_date):
    return long_date.split(",")[0]
def shorten_to_date(long_date):
    return long_date[:long_date.index(',')]


반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

0129. Super Duper Easy  (0) 2023.01.29
0128. Gauß needs help! (Sums of a lot of numbers).  (0) 2023.01.28
0126. Over The Road  (0) 2023.01.27
0125. Counting sheep...  (0) 2023.01.25
0124. Regular Ball Super Ball  (0) 2023.01.24