Here I show you another way to do it using sets comprehension and the functions split()
and join()
, so you have variety:
fechas_lista = sorted({"".join(fecha.split()) for fecha in date})
When creating a set, the repeated elements disappear automatically. In this way, even in the case of having a date list as follows:
date = ['Jul 07', ' Jul 07', 'Jul 08', 'Jul 08 ']
The resulting list would not obtain repeated data because the set is about the dates with the spaces already removed, therefore the file automatically deletes elements repeated by the content, even if they have different blank spaces.
As the elements of the set do not have any predefined order, when calling sorted()
passing it as an argument to the resulting set, you are sure of two things: you get a list and it is also ordered.
PD: Identifiers that start with a capital letter are often used to create classes or data types instead of variables.