Harry Potter is learning different spells. He has a list of spells and a list of power values. He wants to join each spell with its power in a single list – to print it using the delimiter "-" and to start and end the collection with "|". Please help Harry print the string representation of the Harry Potter' Spell List.
Collection transformations
Harry and the Spell Power
Report a typo
Sample Input 1:
Expetum-98 Patronus-23 Axio-89 Lithigum-23Sample Output 1:
|(Expetum, 98)-(Patronus, 23)-(Axio, 89)-(Lithigum, 23)|Write a program in Kotlin
data class Spell(val name: String, val power: Int)
fun main() {
val input = readln().split(" ")
val spells = input.map { Spell(it.split("-")[0], it.split("-")[1].toInt()) }
val spellNames = spells.map { spell -> spell.name }
val spellPowers = spells.map { spell -> spell.power }
// write your code here
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.