버미다

고정 헤더 영역

글 제목

메뉴 레이어

버미다

메뉴 리스트

  • 홈
  • 태그
  • 방명록
  • 분류 전체보기 (251) N
    • html, css (83)
    • 서문 (3)
    • python (125) N
    • c언어 (13)
    • gpt활용 (1)
    • pymysql (17)
    • SQLD (8)
    • 업무 (1)

검색 레이어

버미다

검색 영역

컨텐츠 검색

python

  • 딕셔너리 조건

    2024.07.04 by bumychoi

  • 딕셔너리 추가 하기

    2024.07.04 by bumychoi

  • 딕셔너리 합

    2024.07.04 by bumychoi

  • 중복제거

    2024.07.04 by bumychoi

  • range 심화 2

    2024.07.04 by bumychoi

  • range 심화

    2024.07.04 by bumychoi

  • range 함수

    2024.07.04 by bumychoi

  • 리스트 조회

    2024.07.04 by bumychoi

딕셔너리 조건

d={"a":8,"b":33,"c":15,"d":26,"e":12,"f":120}dict_1={}for k,v in d.items():    if v > 25:        dict_1[k]=vprint(dict_1)# 방법2ex2={k:v for k,v in d.items() if v>20}print(f' ex2 결과:{ex2}')print(dict(((k,v)for k,v in d.items() if v>=20)))#방법3ex3 = dict(filter(lambda v:v[1]>=25, d.items()))print(f'ex3 결과:{ex3}')

python 2024. 7. 4. 21:26

딕셔너리 추가 하기

d={"a":"apple","b":"grape"}d["c"]="banana"d["d"]="kiwi"print(d)e={"a":"apple","b":"grape"}c={"c":"banana","d":"kiwi"}e.update(c)print(e)

python 2024. 7. 4. 20:59

딕셔너리 합

d={"a":17,"b":114,"c":247,"d":362,"e":220,"f":728,"g":-283,"h":922}print(d.values())# 방법1total =0for i in d.values():    total += iprint(f'ex1 결과 {total}')#방법2print(f'ex2 결과 {sum(d.values())}')#방법3print(f'ex3 결과 {sum([d[item] for item in d])}')

python 2024. 7. 4. 20:40

중복제거

#제거x=["a",1,"b",2,"a",3,"b",4,5,"b"]# 방법1 - 순서가 없음y=list(set(x))print(y)#순선유지from collections import OrderedDictex2 =list(OrderedDict.fromkeys(x))print(f'ex2 결과:{ex2}')# 방법3- 순서유지ex3=[]for i in x:    if i not in ex3:        ex3.append(i)print(ex3)print("-------------")

python 2024. 7. 4. 20:23

range 심화 2

li=[]for i in range(1,16):    i*=10    li.append(str(i))print(li)# 빙법2print(list(map(lambda x:str(x*10),range(1,16))))# 방법3print([str(x*10) for x in range(1,16)])

python 2024. 7. 4. 20:06

range 심화

[10, 2, 30, 4, 50, 6, 70, 8, 90, 10, 110, 12, 130, 14, 150, 16, 170, 18, 190, 20] [10, 2, 30, 4, 50, 6, 70, 8, 90, 10, 110, 12, 130, 14, 150, 16, 170, 18, 190, 20] li=[]for i in range(1,21): if i%2==0: li.append(i) else: i=i*10 li.append(i)print(li)x=[x *10 if x %2 !=0 else x for x in range(1,21)]print(x) print([[j for j in range(5)]for i in range(5)]) [[0, 1, 2,..

python 2024. 7. 4. 19:48

range 함수

#방법1ex1=[]for i in range(30,-12,-2): ex1.append(i)print(ex1)#방법2ex2=list(range(30,-12,-2))print(ex2)

python 2024. 7. 4. 19:39

리스트 조회

x=["grapes","mango","orange","peach","kiwi","apple","lime","cherry","tomato","blueberry","watermelon"]a=[]for i in x: if i == "apple" or i=="kiwi": a.append(i.upper())print(a)# 추가 방법# 방법1ex1=[]for i in range(len(x)): if x[i] == "apple" or x[i] =="kiwi": ex1.append(x[i].upper())print(f'ex1 결과:{ex1}')# 방법2ex2=map(lambda b:b.upper(),(filter(lambda a:a=="apple" or a=="kiwi",x)))..

python 2024. 7. 4. 19:23

추가 정보

인기글

최신글

페이징

이전
1 ··· 3 4 5 6 7 8 9 ··· 16
다음
TISTORY
버미다 © Magazine Lab
페이스북 트위터 인스타그램 유투브 메일

티스토리툴바