E
E
ekzotika2020-05-21 23:02:47
Python
ekzotika, 2020-05-21 23:02:47

How to write a for loop to iterate over the sequences that are written in the body of the question?

I need to get something like this:

[{
«name»: «Tulip Serenade»,
«days»: 8,
«itinerary»: [amsterdam,amsterdam,arnhem …..],
«dates»:[
{«2019-04-04»:{«ship»: «ms amadeus queen», «price»:1044.65},
...(остальные даты)}
],
},..]


"name", "days" and "itinerary" are fine, but what about "dates"? I have 3 lists: date, ship and price. I am trying to do like this:

for a, b, c in zip(date, ship, price):
     dates = [{a: {'ship': b, 'price': c}}]


data = [{'name': name,
        'days': days,
        'itinerary': itinerary,
        'dates': dates
        }]


But I'm getting

[[{'name': 'Tulip Serenade', 'days': ' 8', 'itinerary': [' Amsterdam ', ' Amsterdam ', ' Arnhem ', ' Middelburg ', ' Ghent ', ' Antwerp ', ' Rotterdam ', ' Amsterdam '], 'dates': [{'26. Apr 2021 - 03. May 2021': {'ship': 'MS Amadeus Silver III', 'price': ' € 1.619,00 '}}]}]

instead of multiple "dates" even though there is data in there! What should I do, please help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question