Python3 is completely free on Paiza, so I summarized it.
lesson.py
Text data(Key)Handle with
list
for list 012
list[0]="monster"
list[1]="Dragon"
list[2]="Devil"
dictionary
dict Zako middle boss last boss
dict["Zako"]="monster"
dict["Medium boss"]="Dragon"
dict["Las boss"]="Devil"
Can be done like
Basic function of dictionary
enemies Zako middle boss last boss
Browse data with key
print(enemies["Zako"])
Find the key variable
level="Medium boss"
print(enemies[level])
The number of data
print(len(enemies))
Can be added, updated and deleted
Dictionary usage
1.Processing of data exchanged with DB
Score list data(Column)→ Process with list
National language score
2.Processing of data that interacts with the API
Student record(Row)→ Dictionary(dictionary)Processed by
Attendance number, national language, math, English
lesson.py
#List review
enemyArray=["Slime","monster","Dragon"]
print(enemyArray)
print(enemyArray[0])
#Specific example of dictionary
enemyDictionary= {"Zako":"Slime","Medium boss":"Dragon","Las boss":"Devil"}
print(enemyDictionary)
print(enemyDictionary["Zako"])
print(enemyDictionary["Medium boss"])
level= "Zako"
print(enemyDictionary[level])
level="Las boss"
print(enemyDictionary[level])
#Anything that does not exist will result in an error
#print(enemyDictionary["enemy"])
lesson.py
print(enemyArray)
['Slime', 'monster', 'Dragon']
print(enemyArray[0])
Slime
print(enemyDictionary)
{'Zako': 'Slime', 'Medium boss': 'Dragon', 'Las boss': 'Devil'}
print(enemyDictionary["Zako"])
Slime
print(enemyDictionary["Medium boss"])
Dragon
level= "Zako"
Slime
level="Las boss"
Devil
lesson.py
skills = {"Profession":"Warrior", "Physical fitness":100, "Magical power":200,"gold":380}
print(skills)
lesson.py
skills = {"Profession":"Warrior", "Physical fitness":100, "Magical power":200, "gold":380}
#Below this, let's output the dictionary
print(skills)
lesson.py
skills = {"Profession":"Warrior", "Physical fitness":100, "Magical power":200, "gold":380}
#Below this, let's output from the dictionary
print(skills["Profession"])
lesson.py
#Basic operation of dictionary
enemies = {"Zako":"Slime", "Medium boss":"Dragon", "Las boss":"Devil"}
print(enemies)
print(enemies["Zako"])
print(enemies["Medium boss"])
#You can get the number of dictionaries
print(len(enemies))
#Can be added to the dictionary
enemies["Zako 2"]="Metal monster"
print(enemies)
print(len(enemies))
#Change value
enemies["Medium boss"]="Red Dragon"
print(enemies)
print(len(enemies))
#Delete value
del enemies["Zako"]
print(enemies)
print(len(enemies))
lesson.py
skills = {"Profession":"Warrior", "Physical fitness":100, "Magical power":200, "gold":380}
#Below this, let's output the length of the dictionary
print(len(skills))
lesson.py
skills = {"Profession":"Warrior", "Physical fitness":100, "Magical power":200, "gold":380}
#Below this, let's add data to the dictionary
skills["attribute"]="flame"
print(skills)
lesson.py
skills = {"Profession":"Warrior", "Physical fitness":100, "Magical power":200, "gold":380}
print(skills)
#Below this, let's update the hash
skills["Profession"]="Wizard"
print(skills)
lesson.py
skills = {"Physical fitness" : 100,"Profession" : "Warrior", "Magical power" : 200, "gold" : 380}
print(skills)
#Below this, let's delete the dictionary
del skills["Physical fitness"]
print(skills)
lesson.py
#Review of the dictionary
enemies = {"Zako":"Slime", "Medium boss":"Dragon", "Las boss":"Devil"}
print(enemies)
print(enemies["Zako"])
print(enemies["Medium boss"])
#Loop processing
for rank in enemies:
print(enemies[rank] + "However, it appeared!")
#Use the items method to retrieve dictionary keys and values in pairs
for (rank,enemy) in enemies.items():
print(rank + "of" + enemy + "However, it appeared!")
lesson.py
skills = {"Profession" : "Warrior", "Physical fitness" : 100, "Magical power" : 200, "gold" : 380}
#Below this, let's output the dictionary value in a loop
for i in skills:
print(skills[i])
lesson.py
skills = {"Profession" : "Warrior", "Physical fitness" : 100, "Magical power" : 200, "gold" : 380}
#Below this, let's output the hash value in a loop
for(key,item) in skills.items():
print(key + "Is" + str(item) + "is")
lesson.py
points = {"National language" : 70, "arithmetic" : 35, "English" : 52}
sum = 0
#Below this, let's calculate the sum of the dictionary values in a loop
for key in points:
sum +=points[key]
print(sum)
lesson.py
#Sorting the list
weapons=["Aegis Sword","Wind Spear","Earth breaker","Inazuma Hammer"]
print(weapons)
#Aiueo order
print(sorted(weapons))
#Opposite of Aiueo order
print(sorted(weapons,reverse=True))
wepons2=["4.Aegis Sword","1.Wind Spear","3.Earth breaker","2.Inazuma Hammer"]
#Numbers>In order of Aiueo
print(sorted(wepons2))
wepons3=["4.Aegis Sword","1 Wind Spear","1 Earth breaker","2.Inazuma Hammer"]
#If there are the same numbers, the order of Aiueo will be prioritized.
print(sorted(wepons3))
wepons4=["Burning sword","Fujin Spear","Earth breaker","Lightning hammer"]
#Be careful when kanji and katakana are mixed!Sometimes not sorted
print(sorted(wepons4))
lesson.py
['Aegis Sword', 'Wind Spear', 'Earth breaker', 'Inazuma Hammer']
['Earth breaker', 'Inazuma Hammer', 'Aegis Sword', 'Wind Spear']
['Wind Spear', 'Aegis Sword', 'Inazuma Hammer', 'Earth breaker']
['1.Wind Spear', '2.Inazuma Hammer', '3.Earth breaker', '4.Aegis Sword']
['1 Earth breaker', '1 Wind Spear', '2.Inazuma Hammer', '4.Aegis Sword']
['Burning sword', 'Earth breaker', 'Lightning hammer', 'Fujin Spear']
lesson.py
apples = [310, 322, 292, 288, 300, 346]
#Here is the code to sort and display the elements
print(sorted(apples))
lesson.py
apples = [310, 322, 292, 288, 300, 346]
Here is the code to sort and display the elements
print(sorted(apples,reverse=True))
lesson.py
words = ["pumpkin", "orange", "apple", "carrot", "onion"]
#Here is the code to sort and display the elements
print(sorted(words))
lesson.py
weapons={"Aegis Sword":40,"Wind Spear":12,"Earth breaker":99}
#Display as a dictionary
print(sorted(weapons))
print(weapons)
#Sort dictionary by key(Alignment)To do
#Tuple: A type of data structure, contents cannot be updated
#A data structure that manages various values collectively like a list.
print(sorted((weapons).items()))
lesson.py
math = {"Good" : 12, "Pea" : 99, "Adachi" : 40}
#Below this, let's sort the dictionary by key and output it
#Aligning dictionaries
#Display as a dictionary
print(sorted(math))
lesson.py
#Sort the dictionary and output it in the dictionary
math = {"Pea" : 99, "Adachi" : 40, "Good" : 12}
#Below this, let's sort the dictionary by key and output it as a dictionary
print(sorted((math).items()))
lesson.py
Item List:Display multiple item images
Sword, vertical, healing medicine, healing medicine, crystal
1.Display item image and item name
2.I want to display the same item multiple times
3.I want to manage the order of items
4.Share one file of the same item image
Combine dictionaries and arrays
Sort order list item_oders
|Sort order|Item name|
| ---- | ---- |
| 0 |crystal|
| 1 | "sword" |
| 2 | "Recovery agents" |
| 3 | "shield" |
↓item_Use orders as a key to retrieve the image file of ↓
Image dictionary item.images
|Item name|Image file|
| ---- | ---- |
|sword|Image of sword|
|crystal|Crystal image|
|shield|Shield image|
|Recovery agents|Image of recovery drug|
If you code this,
item_orders[0]→itemimages[item_orders[0]]→ Crystal image file
item_orders[1]→itemimages[item_orders[1]]→ Sword
:
:
I want to make a program that repeats
lesspn.py
#Image hash
item_images = {
"sword":"http://paiza.jp/learning/images/sword.png ",
"shield":"http://paiza.jp/learning/images/shield.png ",
"Recovery agents":"http://paiza.jp/learning/images/potion.png ",
"crystal":"http://paiza.jp/learning/images/crystal.png "
}
#Item order arrangement
items_order = ["crystal", "shield", "sword", "Recovery agents", "Recovery agents", "Recovery agents"]
#print(item_images)
#print(items_order)
lesson.py
for item_name in items_order:
print(item_name)
output
crystal
shield
sword
Recovery agents
Recovery agents
Recovery agents
lesson.py
#Extract the item name
for item_name in items_order:
print(item_images[item_name])
print(item_name)
http://paiza.jp/learning/images/crystal.png
crystal
http://paiza.jp/learning/images/shield.png
shield
http://paiza.jp/learning/images/sword.png
sword
http://paiza.jp/learning/images/potion.png
Recovery agents
http://paiza.jp/learning/images/potion.png
Recovery agents
http://paiza.jp/learning/images/potion.png
Recovery agents
lesson.py
#Extract the item name
for item_name in items_order:
print("<img src='"+item_images[item_name]+"'>")
print(item_name+"<br>")
<img src='http://paiza.jp/learning/images/crystal.png'>
crystal
<img src='http://paiza.jp/learning/images/shield.png'>
shield
<img src='http://paiza.jp/learning/images/sword.png'>
sword
<img src='http://paiza.jp/learning/images/potion.png'>
Recovery agents
<img src='http://paiza.jp/learning/images/potion.png'>
Recovery agents
<img src='http://paiza.jp/learning/images/potion.png'>
Recovery agents
lesson.py
items_imges = {
"sword" : "http://paiza.jp/learning/images/sword.png ",
"shield" : "http://paiza.jp/learning/images/shield.png ",
"Recovery agents" : "http://paiza.jp/learning/images/potion.png ",
"crystal" : "http://paiza.jp/learning/images/crystal.png "
}
#Item order list
items_orders = ["sword", "shield", "Recovery agents", "crystal"]
#Let's write below from here
for item_name in items_orders:
print("<img src='"+items_imges[item_name]+"'><br>")
lesson.py
input
6
Recovery agents
shield
crystal
crystal
sword
sword
#Image dictionary
items_imges = {
"sword" : "http://paiza.jp/learning/images/sword.png ",
"shield" : "http://paiza.jp/learning/images/shield.png ",
"Recovery agents" : "http://paiza.jp/learning/images/potion.png ",
"crystal" : "http://paiza.jp/learning/images/crystal.png "
}
#Let's write below from here
#Assign the number of items to be output to a variable
item_cnt = int(input())
#Output items in standard input
while item_cnt > 0:
item = input()
print("<img src = '" + items_imges[item] + "'>")
item_cnt = item_cnt - 1
output
<img src = 'http://paiza.jp/learning/images/potion.png'>
<img src = 'http://paiza.jp/learning/images/shield.png'>
<img src = 'http://paiza.jp/learning/images/crystal.png'>
<img src = 'http://paiza.jp/learning/images/crystal.png'>
<img src = 'http://paiza.jp/learning/images/sword.png'>
<img src = 'http://paiza.jp/learning/images/sword.png'>
Recommended Posts