[ENG] STEEM Security update - added power down alert

by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/eng-steem-security-update-added-power-down-alert STEEM Security - receive STEEM alert messages via Discord Hello, this is @joviansummer(witness: @jswit). STEEM Security code has been revised. Previously, STEEM Security was sending alert message via discord for the following 3 kinds of operations: sending STEEM/SBD to another account changing SP delegation account update Now, power down operation has been added. If there is a power down operation, you will also receive alert message. Please check the original post of the above link for detailed information on how to use the service. Thank you for reading, and have a wonderful day! @joviansummer's STEEM projects @jswit witness: I'm running a STEEM witness node. I'd really appreciate it if you vote for my witness account @jswit. ( https://steemitwallet.com/~witnesses ) [ENG] Introducing @jswit witness project @jsup curation: [ENG] Int...

파이썬 딕셔너리(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

[ENG] jsup 2.0 - make your upvote great again

jsup/avle 보팅 코드 갱신 - 1일1포스팅 강박에서 벗어나기

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