periodsList = []
su = '0:'
Su = []
sun = []
SUN = ''
変換して時刻表をフォーマットしています
extendedPeriods = ['0: 1200 - 1500',
'0: 1800 - 2330',
'2: 1200 - 1500',
'2: 1800 - 2330',
'3: 1200 - 1500',
'3: 1800 - 2330',
'4: 1200 - 1500',
'4: 1800 - 2330',
'5: 1200 - 1500',
'5: 1800 - 2330',
'6: 1200 - 1500',
'6: 1800 - 2330']
の中へ'1200 - 1500/1800 - 2330'
- su は日の識別子です
- Su、sun いくつかの値を保存する
SUN は変換された時刻表を保存します
for line in extendedPeriods: if su in line: Su.append(line) for item in Su: sun.append(item.replace(su, '', 1).strip()) SUN = '/'.join([str(x) for x in sun])
次に、「コンバーター」を他の日にも適用する関数を作成しようとしました..
def formatPeriods(id, store1, store2, periodsDay):
for line in extendedPeriods:
if id in line:
store1.append(line)
for item in store1:
store2.append(item.replace(id, '', 1).strip())
periodsDay = '/'.join([str(x) for x in store2])
return periodsDay
しかし、この関数は 12 個の形式の誤った文字列を返します...
'1200 - 1500', '1200 - 1500/1200 - 1500/1800 - 2330',