Dictionaries

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
The sea does not like to be restrained.
Emektar Üye
Katılım
15 Tem 2021
Mesajlar
1,724
Çözümler
86
Tepki puanı
665
Ödüller
10
Yaş
25
Sosyal
4 HİZMET YILI
In Python, a dictionary is a collection of key-value pairs. Each key is unique and is used to access its corresponding value. Here's an example of a simple dictionary:

Python:
person = {
    "name": "Alice",
    "age": 30,
    "occupation": "Engineer"
}

In this example, we define a dictionary called person with three key-value pairs. The keys are "name", "age", and "occupation", and the corresponding values are "Alice", 30, and "Engineer".

You can access the values of a dictionary using the keys. For example:

Python:
print(person["name"])
print(person["age"])
print(person["occupation"])

This would output:

Python:
Alice
30
Engineer

You can also modify the values of a dictionary by assigning new values to its keys. For example:

Python:
person["age"] = 31
print(person["age"])

This would output:


Python:
31

You can add new key-value pairs to a dictionary by assigning a value to a new key. For example:

Python:
person["city"] = "New York"
print(person["city"])

This would output:


Python:
New York

You can use the del keyword to delete a key-value pair from a dictionary. For example:

Python:
del person["occupation"]
print(person)

This would output:

Python:
{'name': 'Alice', 'age': 31, 'city': 'New York'}

You can also loop through a dictionary using a for loop. For example:


Python:
for key in person:
    print(key, person[key])

This would output:


Python:
name Alice
age 31
city New York
 
Onaylı Üye
Katılım
1 Nis 2019
Mesajlar
93
Tepki puanı
5
Ödüller
4
Yaş
27
7 HİZMET YILI
That's great. I didn't think you could do so much in python.
 
Tired of cheating
Süper Üye
Katılım
16 Haz 2018
Mesajlar
1,338
Çözümler
4
Tepki puanı
147
Ödüller
10
Yaş
33
7 HİZMET YILI
In Python, a dictionary is a collection of key-value pairs. Each key is unique and is used to access its corresponding value. Here's an example of a simple dictionary:

Python:
person = {
    "name": "Alice",
    "age": 30,
    "occupation": "Engineer"
}

In this example, we define a dictionary called person with three key-value pairs. The keys are "name", "age", and "occupation", and the corresponding values are "Alice", 30, and "Engineer".

You can access the values of a dictionary using the keys. For example:

Python:
print(person["name"])
print(person["age"])
print(person["occupation"])

This would output:

Python:
Alice
30
Engineer

You can also modify the values of a dictionary by assigning new values to its keys. For example:

Python:
person["age"] = 31
print(person["age"])

This would output:


Python:
31

You can add new key-value pairs to a dictionary by assigning a value to a new key. For example:

Python:
person["city"] = "New York"
print(person["city"])

This would output:


Python:
New York

You can use the del keyword to delete a key-value pair from a dictionary. For example:

Python:
del person["occupation"]
print(person)

This would output:

Python:
{'name': 'Alice', 'age': 31, 'city': 'New York'}

You can also loop through a dictionary using a for loop. For example:


Python:
for key in person:
    print(key, person[key])

This would output:


Python:
name Alice
age 31
city New York
I will try and let you know brother
 
Onaylı Üye
Katılım
16 Tem 2021
Mesajlar
51
Tepki puanı
3
Ödüller
2
Yaş
37
4 HİZMET YILI
Soy de argentina y de esta web saque varias cosas de python! , gracias
 
Üye
Katılım
24 Eki 2020
Mesajlar
41
Tepki puanı
0
Ödüller
2
Yaş
27
5 HİZMET YILI
Soy de argentina y de esta web saque varias cosas de python
 
Banlı Üye
Katılım
12 Tem 2023
Mesajlar
382
Tepki puanı
21
Yaş
27
2 HİZMET YILI
Oh thank you, I’ll need that in the future
 
Onaylı Üye
Katılım
5 Şub 2022
Mesajlar
50
Tepki puanı
2
Ödüller
2
Yaş
25
4 HİZMET YILI
def roundtrip(df):
a, b, c, d = 'station from', 'station to', 'count', 'count_back'
idx = df[a] > df
df = df.assign(**{d: 0})
df.loc[idx, [a, b, c, d]] = df.loc[idx, [b, a, d, c]].values
return df.groupby([a, b]).sum()
 
Onaylı Üye
Katılım
14 Tem 2020
Mesajlar
51
Tepki puanı
1
Ödüller
4
Yaş
30
5 HİZMET YILI
Time complexity for lookup on dictionary is O(1)
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst