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)에서 특정 키(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

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

[ENG] jsup 2.0 - make your upvote great again

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