文章からメッセージの振り分け。
入力データ
1kara2he xxxx1
3kara1he xxxx2
2kara1he xxxx3
3kara1he xxxx4
python
1#l=[] 2#[l.append(input().split()) for _ in range(4)] 3完成するデータ 4l=[ 5['1kara2he', 'xxxx1'], 6['3kara1he', 'xxxx2'], 7['2kara1he', 'xxxx3'], 8['3kara1he', 'xxxx4'] 9] 10 11import re 12[r.append(re.findall(r'(\d+|\D+)',i[0])) for i in l] 13[print(i) for i in r] 14 15#処理済みデータ 16""" 17['1', 'kara', '2', 'he'] 18['3', 'kara', '1', 'he'] 19['2', 'kara', '1', 'he'] 20['3', 'kara', '1', 'he'] 21"""
この時に
python
1 2 3A1=[]#A1は仮の配列名で作成済みの配列 4A2=[]# 々 5A3=[]# 々 6for i in r: 7 if i[3]=='he': #heは送るの意味 8 if int(i[0])==1 and int(i[2])==2:#ここを自動化したい 9 A1.append(l[0][1])#送信者 10 A2.append(l[0][1])#受信者 11print(A1,A2)#確認
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。