[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)에서 특정 키(key)가 존재하는지 확인하기

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


key:value 형태로 구성되는 딕셔너리(dict) 형식의 변수에서 특정한 키(key)가 포함되어 있는지 확인하는 방법입니다.

일단 아래와 같이 x_dict라는 변수를 생각해 봅니다.

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

x_dict에 "def"라는 키가 있는지 확인하려면 간단하게 if 조건문으로 가능합니다.

if 'def' in x_dict:
  print('x_dict에 키 def가 존재합니다.')
else:
  print('x_dict에 키 def가 존재하지 않습니다.')

딕셔너리의 value 항목을 리스트(list) 또는 딕셔너리로 구성하려면 실제 값을 할당하기 전에 초기화를 해 주어야 하는데, 이와 관련하여 간단한 예시를 메모해 둡니다.

target_list = { 'abc':[1,2,3] }
target_key = 'def'

if target_key in target_list:
  # value에 10을 추가, 리스트 형태이므로 append() 사용
  target_list[target_key].append(10)
else:
  print("target_list에 ", target_key, "키가 없습니다."
  # value를 리스트 형식으로 선언한 후에 value에 10을 추가
  target_list[target_key] = []
  target_list[target_key].append(10)

print(target_list)

{'abc': [1, 2, 3], 'def': [10]}

Comments

Popular posts from this blog

[ENG] jsup 2.0 - make your upvote great again

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

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