Dictionaries: Gold Challenge Solutions

Just contributing to this forum. First time! Below is my code for the Gold solution:

var blueDevilsPlayers = [“Matt”, “John”, “Cuda”, “Reba”, “Alex”]
var cavaliersPlayers = [“John1”, “Maria”, “Ari”, “Carmelo”, “Betsy”]
var crusadersPlayers = [“Ramona”, “Frank”, “Ore”, “Sean”, “Zach”]

var blueDevilsList = blueDevilsPlayers.joined(separator: “\n”)
var cavaliersList = cavaliersPlayers.joined(separator: “\n”)
var crusadersList = crusadersPlayers.joined(separator: “\n”)

var dciLeague = [“BlueDevils”: blueDevilsPlayers, “Cavaliers”: cavaliersPlayers, “Crusaders”: crusadersPlayers]

var dciLeagueList = [“BlueDevils”: blueDevilsList, “Cavaliers”: cavaliersList, “Crusaders”: crusadersList]

print(“The dci league has the following players: (dciLeague.values)\n”)

for (key, value) in dciLeagueList{
print("(key):", “(value)”, separator: “\n”, terminator: “\n\n”)
}

I could not resist beautifying your code, with minor corrections in the print statements, by including it between a pair of three back-tick characters like this :slight_smile:

```
Your Code
```

var blueDevilsPlayers = ["Matt", "John", "Cuda", "Reba", "Alex"]
var cavaliersPlayers  = ["John1", "Maria", "Ari", "Carmelo", "Betsy"]
var crusadersPlayers  = "“Ramona", "Frank", "Ore", "Sean", "Zach"]

var blueDevilsList = blueDevilsPlayers.joined (separator: "\n")
var cavaliersList  = cavaliersPlayers.joined (separator: "\n")
var crusadersList  = crusadersPlayers.joined (separator: "\n")

var dciLeague = ["BlueDevils": blueDevilsPlayers, "Cavaliers": cavaliersPlayers, "Crusaders": crusadersPlayers]

var dciLeagueList = ["BlueDevils": blueDevilsList, "Cavaliers": cavaliersList, "Crusaders": crusadersList]

print ("The dci league has the following players: \(dciLeague.values)\n")

for (key, value) in dciLeagueList {
     print ("\(key): \(value)", separator: "\n", terminator: "\n\n")
}

Let’s farewell the year 2020, and welcome the 2021!

Wishing everyone a safe and happy new year…

1 Like

Thank you very much Ibex! Have a happy new year!