Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2023-2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mohamed.abouhoula@studenti.unimi.it
2023-2024
Commits
d024f703
Commit
d024f703
authored
Nov 29, 2023
by
Anna Morpurgo
Browse files
Options
Downloads
Patches
Plain Diff
Lab08.md - note su stampa di mappe
parent
116656ab
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Lab08.md
+30
-2
30 additions, 2 deletions
Lab08.md
with
30 additions
and
2 deletions
Lab08.md
+
30
−
2
View file @
d024f703
...
...
@@ -102,18 +102,46 @@ Accesso al valore di una mappa associato a una data chiave:
value = myMap[key]
```
Cancellazione di un elemento (quindi della coppia chiave:valore) da una mappa:
####
Cancellazione di un elemento (quindi della coppia chiave:valore) da una mappa:
```
go
delete(myMap, key)
```
Verifica della presenza di una chiave in una mappa:
####
Verifica della presenza di una chiave in una mappa:
```
go
value, ok = myMap[key]
//se key c'è in myMap, ok è true e value è il valore associato a key;
//altrimenti ok è false e value è lo zero-value associato al tipo per i valori della mappa
```
#### Stampa di una mappa
(gli esempi qui di seguito hanno chiavi di tipo int, ma la stessa impostazione è valida anche per mappe con chiavi di altro tipo)
```
go
// stampa dell'intera mappa
fmt.Println(myMap)
// stampa elemento per elemento, non importa in che ordine
for key, value := range myMap {
fmt.Println(key, value)
}
// stampa elemento per elemento, in ordine crescente di chiave, chiavi non presenti (con valore zero) incluse
for key := min; key <= max; key++ {
fmt.Println(key, myMap[key])
}
// stampa elemento per elemento, in ordine crescente di chiave, chiavi non presenti escluse
for key := min; key <= max; key++ {
if value, ok := myMap[key]; ok {
fmt.Println(key, value)
}
}
```
#### Verifica di uguaglianza
Per verificare se due mappe sono uguali, vedete la funzione `DeepEqual` del package `reflect`.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment