Last active
December 12, 2015 07:28
-
-
Save keitheis/4737108 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # encoding: utf8 | |
| # Kanban of Python Taiwan in Early November | |
| # Python Quest #2 | |
| dates = ['1 year, 10 months, 15 days', | |
| '2 years, 1 month, 15 days', | |
| '1 month, 15 days', | |
| '1 year', | |
| '2 months', | |
| '15 days', | |
| '1 days', | |
| '2 year, 1 month, 1 day'] | |
| print dates | |
| def _(string): | |
| # Fake translation for testing | |
| if string in ('year', 'years'): | |
| return 'Y' | |
| elif string in ('month', 'months'): | |
| return 'M' | |
| elif string in ('day', 'days'): | |
| return 'D' | |
| return string | |
| # Q: how to translate all English unit to Chinese? | |
| # For example: | |
| # ['1 年, 10 個月, 15 天', | |
| # '2 年, 1 個月, 15 天', | |
| # '1 個月, 15 天', | |
| # ... | |
| new_dates = [] | |
| for date in dates: | |
| new_pieces = [] | |
| for piece in date.split(','): | |
| number, unit = piece.strip().split(" ") | |
| new_pieces.append(number + " " + _(unit)) | |
| new_dates.append(', '.join(new_pieces)) | |
| print new_dates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment