Python Forum

Full Version: Lists + Empty Lists
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Sorry if this is stupid but I have created a list of days

days = ['Monday','Tuesday', 'Wednesday', 'Thursday','Friday', 'Saturday', 'Sunday']

I am trying to assign the weekdays to an empty list:
weekdays = []

and the weekend days to an empty list:
weekends = []

I can't figure out how to assign the days properly, would I use a while loops or a for loop? Or would I need to loop them at all?
Sorry again if it's a stupid question.
days = ['Monday','Tuesday', 'Wednesday', 'Thursday','Friday', 'Saturday', 'Sunday']
weekdays = days[:5]
weekends = days[5:]

print(weekdays)
print(weekends)
Output:
['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] ['Saturday', 'Sunday']
(Mar-22-2021, 06:47 PM)Axel_Erfurt Wrote: [ -> ]
days = ['Monday','Tuesday', 'Wednesday', 'Thursday','Friday', 'Saturday', 'Sunday']
weekdays = days[:5]
weekends = days[5:]

print(weekdays)
print(weekends)
Output:
['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] ['Saturday', 'Sunday']

Hey Axel,

Thanks so much but does this mean I'm assigning the days to empty lists or am I just printing the first five and then anything after the first five?

Thanks again
They are not empty

weekdays is a new list with the week days
weekends is a new list with the weekend days
(Mar-22-2021, 06:52 PM)Axel_Erfurt Wrote: [ -> ]They are not empty

weekdays is a new list with the week days
weekends is a new list with the weekend days

I see thank you, do you know a way to assign the days to two separate empty lists?
Hint:
>>> import calendar
>>> for num, day in enumerate(calendar.day_name):
...     print(num, day)
... 
0 Monday
1 Tuesday
2 Wednesday
3 Thursday
4 Friday
5 Saturday
6 Sunday
>>>
(Mar-22-2021, 06:59 PM)Larz60+ Wrote: [ -> ]Hint:
>>> import calendar
>>> for num, day in enumerate(calendar.day_name):
...     print(num, day)
... 
0 Monday
1 Tuesday
2 Wednesday
3 Thursday
4 Friday
5 Saturday
6 Sunday
>>>

Hi, Thanks so much for getting back to me.
Would I be right in thinking that I would need to print number 0-4 and assign them to the first empty list and then assign the 5-6 to the second empty list?

It's how to assign it that I'm mainly having trouble with.

Sorry :(
Would something like this work:

days = ['Monday','Tuesday', 'Wednesday', 'Thursday','Friday', 'Saturday', 'Sunday']

#Create empty lists for weekdays and weekends
weekdays = []
weekends = []


index = 0
while index < len(days):
day = days[index]
print( days )
index = index + 1
You have a list with all days and you want 2 lists with weekdays and weekend days ?

I wrote it before

weekdays = days[:5]
weekends = days[5:]
(Mar-22-2021, 07:40 PM)Axel_Erfurt Wrote: [ -> ]You have a list with all days and you want 2 lists with weekdays and weekend days ?

I wrote it before

weekdays = days[:5]
weekends = days[5:]

Thank you again for replying, this is what I'm trying to do:

Create a list containing the days of the week from Monday to Sunday and two empty lists weekday = [ ] and weekend = [ ]. Allocate each element from the list containing the days to the appropriate list: either weekday or weekend.

Print the weekdays from the weekday list in the order from Monday to Friday.
Print the weekend days from the weekend list in the order Saturday, Sunday.
Pages: 1 2