-2

I have two lists:

date = ['09.10.2019', '09.10.2019', '09.10.2019']

and

time = ['8:00', '9:00', '10:00']

and I need to create a new one that should look like:

date_time = ['09.10.2019 8:00', '09.10.2019 9:00', '09.10.2019 10:00']

I've already tried to use .append():

```date_time=[]
for element in data:
    date_time.append(date+time)```

, but I'm not able to add a space between them:

date_time = ['09/10/201901:00', '09/10/201902:00', '09/10/201903:00']

Any thoughts?

Thanks

bestzye
  • 45
  • 4
  • 2
    You'll have to add the space yourself, or use string formatting. E.g. `date_time = [f"{d} {t}" for d, t in zip(date, time)]`, which uses formatted strings (requires Python 3.6 or newer). – Martijn Pieters Sep 11 '19 at 15:43

1 Answers1

1

You can use map and zip together with ' '.join:

map(' '.join, zip(date, time))
a_guest
  • 34,165
  • 12
  • 64
  • 118
  • 1
    you may want to note that this will return map object and need to be converted to list, otherwise OP may wonder what to do with map object – buran Sep 11 '19 at 15:46