Hi guys long story short I have a list of data structure that looks like this
Class Event:
start: datetime
end: datetime
Take a list[Event]
, I want to produce a new list that have two entries for each original Event
:
event_a = Event(start=2024-06-14, end=2024-06-15)
event_b = Event(start=2024-07-14, end=2024-07-15)
input_list = [event_a, event_b]
# construct new list here
def construct(input_list: list[Event]) -> list[datetime]:
...
output_list = construct(input_list)
# expected output is
# [2024-06-14, 2024-06-15, 2024-07-14, 2024-07-15]
I know I can do it with list comprehension and I’m wondering can I do it efficiently with a map, I’ve tried
output_list = map(lambda x: (x.start, x.end), input_list)
but this returns
[(2024-06-14, 2024-06-15), (2024-07-14, 2024-07-15)]
Is there a way I can tweak the map lambda that directly return a flatten list instead?
Thank you all!
New contributor
Sunfyr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.