jsup/avle code update - you don't have to write post everyday

by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/jsup-avle-code-update-you-don-t-have-to-write-post-everyday Hello, this is @joviansummer, developer of @jsup and@avle voting service. Voting service code for @jsup and @avle has been updated. I had been considering this update for a while, and recently I could come up with detailed implementation plan which resulted in a relatively swift code revision. The new added feature is capability to give daily upvote to the first thing you write for the day(timezone GMT+9) regardless of post or comment/reply. Writing a post everyday can be challenging. In that case, you can write a reply to receive daily upvote because writing a reply everyday is much easier and also a good way to engage in your community. Writing a post everyday just to get an upvote can be very tedious and exhausting, and post itself could easily become low-quality. There may be people who enjoy writing a post everyday, but we can't ignore th...

파이썬 딕셔너리(dict)에서 원소 추가/제거

by joviansummer
original STEEMIT post: https://steemit.com/blog/@joviansummer/dict


파이썬에서 key:value 형태로 구성된 딕셔너리(dict)에서 특정 키(key)에 대응하는 원소를 추가/제거하는 방법입니다.

원소 추가는 간단합니다. 변수를 딕셔너리 형식으로 초기화한 후에 원소를 할당해 주면 됩니다.

# x_dict 변수 초기화(딕셔너리 형식)
x_dict = {}
# 원소 추가 - 키 'abc', 값 100
x_dict['abc'] = 100
# 2개 더 추가
x_dict['def'] = 50
x_dict['xyz'] = 99

당연히 아래와 같이 변수 x_dict의 내용을 한번에 할당해도 됩니다.

x_dict = { 'abc':100, 'def':50, 'xyz':99 }

이제 제거해 보겠습니다. x_dict에서 키 'def'에 대응하는 원소를 제거하려면 pop()을 사용합니다. 아래와 같습니다.

x_dict.pop('def')

이제 x_dict의 내용을 확인해 보면 해당 원소가 사라진 것으로 볼 수 있습니다.

print(x_dict)

{'abc': 100, 'xyz': 99}

제거하면서 해당 원소를 다른 변수에 할당할 수 있습니다. 이번에는 키 'xyz'에 대응하는 원소를 제거하면서 이 값을 변수 y에 할당해 봅니다.

y = x_dict.pop('xyz')

키 'xyz'에 대응하는 값은 99였으므로, 변수 y에 99가 할당되고 x_dict에서는 이 원소가 제거되었습니다.

print(y)

99

print(x_dict)

{'abc': 100}

Comments

Popular posts from this blog

Nuitka - 파이썬 스크립트를 바이너리 실행 파일로 변환

[ENG] jsup 2.0 - make your upvote great again

[EN] STEEM-services: dapps/services webpage with sort and search functions