Lenovo IdeaPad Slim 3 14ABR8 AMD Ryzen 5Lenovo IdeaPad Slim 3 14ABR8 82XL0004ID - ABYSS BLUE = LENOVO SLIM 3 82XL007CID R5-7530U/8GB/512GB/14.0/WIN11+OHS/ABYSS BLUE, Lenovo IdeaPad Slim 3 14ABR8 82XL0005ID - ARCTIC GREY = LENOVO SLIM 3 82XL007BID R5-7530U/8GB/512GB/14.0/WIN11+OHS/ARCTIC GREY Free Klik Disini ! |
Dictionary adalah struktur adata yang bentuknya seperti kamus, mempunya nilai dan kata kunci.
Pada kuliah online sebelumnya kita sudah membahas tentang list dan tuple. Dari tutorial sebelumnya kita bisa membandingkan perbedaan list dan tuple dengan dictionary. Dictionary memiliki kunci berupa teks, bisa juga angka. sedangkan list dan tuple menggunakan indeks berupa angka untuk mengakses nilainya.
apa saja yang bisa kita bisa pelajari dari dictionary ?
users = {'first_name':'dona','last_name':'saputra'}
dari gambar diatas kita dapat mengakses nilai dari key firstname dengan cara
users['first_name']
users.get('first_name')
users['new-key'] = 'key-value']
users={}
users['first_name'] = 'dona'
users['last_name'] = 'saputra'
users['key'] = 'new-value'
del users['key']
fav_languages = {'jen': 'python', 'sarah': 'c', 'edward': 'ruby', 'phil': 'python' }
fav_languages = {'jen': 'python', 'sarah': 'c', 'edward': 'ruby', 'phil': 'python' }
for name, language in fav_languages.items():
print(name +' '+ language)
fav_languages = {'jen': 'python', 'sarah': 'c', 'edward': 'ruby', 'phil': 'python' }for name in fav_languages.items():
print(name)
fav_languages = {'jen': 'python', 'sarah': 'c', 'edward': 'ruby', 'phil': 'python' }for name in sorted(fav_languages.keys()):
print(name)
fav_languages = {'jen': 'python', 'sarah': 'c', 'edward': 'ruby', 'phil': 'python' }len(fav_languages)
programming = [ ]
programming = []
fav_languages = {'jen': 'python', 'sarah': 'c', 'edward': 'ruby', 'phil': 'python' }
programming.append(fav_languages)
fav_languages = {'dona':'java script','rifki':'node js'}
programming.append(fav_languages)
print(programming)
output :
fav_languages = {
'jen': ['python', 'ruby'],
'sarah': ['c'],
'edward': ['ruby', 'go'],
'phil': ['python', 'haskell'],
}for name, langs in fav_languages.items():
print(name + ": ")
for lang in langs:
print("- " + lang)
users = {
'aeinstein': {
'first': 'albert',
'last': 'einstein',
'location': 'princeton',
},
'mcurie': {
'first': 'marie',
'last': 'curie',
'location': 'paris',
}
}
for username, user_dict in users.items():
print("\nUsername: " + username)
full_name = user_dict['first'] + " "
full_name += user_dict['last']
location = user_dict['location']
print("\tFull name: " + full_name.title())
print("\tLocation: " + location.title())
from collections import OrderedDict# Store each person's languages, keeping
# track of who respoded first.fav_languages = OrderedDict()
fav_languages['jen'] = ['python', 'ruby']
fav_languages['sarah'] = ['c']
fav_languages['edward'] = ['ruby', 'go']
fav_languages['phil'] = ['python', 'haskell']# Display the results, in the same order they
# were entered.
for name, langs in fav_languages.items():
print(name + ":")
for lang in langs:
print("- " + lang)
baca artikel lainya :