Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Andrew
intro
Commits
8f229084
Commit
8f229084
authored
Apr 24, 2019
by
JackV
Browse files
Add back lists and dicts
parent
ab3cdbc7
Changes
1
Hide whitespace changes
Inline
Side-by-side
content.md
View file @
8f229084
...
...
@@ -168,6 +168,93 @@ Il segreto degli [hacker](http://www.girodivite.it/Diario-di-un-aspirante-hacker
8
```
----
## Liste (`list`)
-
Collezione
**ordinata**
di elementi, anche di tipi diversi
-
Si definiscono ponendo all'interno di parentesi quadre gli elementi
intervallati da una virgola
```
lista = [False, 1, "due", 3.0, 4, 5]
```
-
Si accede a un elemento della lista aggiungendo l'indice dell'elemento
desiderato tra parentesi quadre
-
Il primo elemento ha indice 0 (zero-based)
```
>>> lista[2]
'due'
```
----
```
>>> lista = [False, 1, "due", 3.0, 4, 5]
>>> lista
[False, 1, 'due', 3.0, 4, 5]
```
```
>>> lista[0] = 0.0
>>> lista
[0.0, 1, 'due', 3.0, 4, 5]
```
```
>>> lista.append('sei')
>>> lista
[0.0, 1, "due", 3.0, 4, 5, 'sei']
```
```
>>> lista.remove('sei')
>>> lista
[0.0, 1, "due", 3.0, 4, 5]
```
```
>>> lista.reverse()
>>> lista
[5, 4, 3.0, 'due', 1, 0.0]
```
```
>>> len(lista)
6
```
----
## Dizionari (`dict`)
-
Associano ogni chiave ad un valore
-
Le chiavi devono essere immutabili (stringhe, tuple)
```
python
d
=
{
"chiave"
:
"valore"
,
"nome"
:
"Tancredi"
,
"cognome"
:
"Orlando"
,
(
'immutable'
,
'types'
):
[
'are'
,
'cool'
]
}
```
Si accede ai campi come si accede agli elementi di una lista, usando la chiave
al posto dell'indice.
```
>>> d['nome']
'Tancredi'
```
```
>>> print('these things ' + ' '.join(d[('immutable', 'types')])
these things are cool
```
---
# Input e Output
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment