Created
February 25, 2015 03:42
-
-
Save linroex/d378e8e8c852a7cb1a83 to your computer and use it in GitHub Desktop.
把 一、三、六 轉成 list
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
# 把 一、三、六 轉成 list | |
def convert_datestr_to_list(date_str): | |
def convert(day): | |
return int(day.replace("一","1").replace("二","2").replace("三","3").replace("四","4").replace("五","5").replace("六","6").replace("日","7")) | |
result = [] | |
for a in date_str.split("、"): | |
b = a.split('~') | |
if len(b) == 1: | |
result.append(convert(b[0])) | |
else: | |
temp = list(range(convert(b[0]), convert(b[1])+1)) | |
result += (temp) | |
return result | |
print(convert_datestr_to_list('一、五~日')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment