bellatrix
bellatrix

Reputation: 139

How to find start and end indices in python dictionary?

My code-

for i, row in df.iterrows():
    thisdict =  {
    row['house']:  "Holding_number"}
print(thisdict)

Result- {'House 193/A': 'Holding_number'} Expected output - {'House 193/A': 0,10 'Holding_number'} I want to add start and end indices. Dataframe- enter image description here

Upvotes: 0

Views: 72

Answers (2)

U13-Forward
U13-Forward

Reputation: 71610

Do you mean by?

lod = []
for i, row in df.iterrows():
    lod.append({row['house']:  f"(0, {len(row['house']) - 1}) {row['label1']}"})
print(lod)

Upvotes: 2

mozway
mozway

Reputation: 261880

Use a dictionary comprehension:

thisdict  = {
    row['house']: (0, len(row['house']-1, row['label1'])
    i, row in df.iterrows()
}

Upvotes: 1

Related Questions