프론트와 데이터 주고 받을 때

api 사용할 때

DB에 낑겨넣을 때

제일 많이 사용하는 형태라 어떻게 만들지 고민해봤다

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    for location in locations:
        a = location.select_one('div > div.header-wrap > div.header-inner-wrap > h2')
        b = location.select_one('div > div.content-wrap > div.description-wrap > p')
 
        if a is not None or b is not None:
            title = a.text
            desc = b.text
 
            # print(title + '\n' + desc + '\n' + image + '\n')
            # 반복문 돌아가며 딕셔너리 배열로 만들기
            locationlist += [{
                'title': title,
                'desc': desc
            }]
 
cs

 

[ {'title':'title','desc':'desc'}, {'title':'title','desc':'desc'}, {'title':'title','desc':'desc'} ]

위와 같은 형태로 만들어진다

 

배열끼리 합칠 때 그냥 + 하면 되길래 해봤는데 된다

 

왜 되는거지...

 

다른 분이 만든걸 봤는데 list에 append 메소드를 사용한다.

append도 사용해 봐야겠다

+ Recent posts