Lists + Empty Lists - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Lists + Empty Lists (/thread-33014.html) Pages:
1
2
|
Lists + Empty Lists - Pytho13 - Mar-22-2021 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. RE: Lists + Empty Lists - Axel_Erfurt - Mar-22-2021 days = ['Monday','Tuesday', 'Wednesday', 'Thursday','Friday', 'Saturday', 'Sunday'] weekdays = days[:5] weekends = days[5:] print(weekdays) print(weekends)
RE: Lists + Empty Lists - Pytho13 - Mar-22-2021 (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) 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 RE: Lists + Empty Lists - Axel_Erfurt - Mar-22-2021 They are not empty weekdays is a new list with the week days weekends is a new list with the weekend days RE: Lists + Empty Lists - Pytho13 - Mar-22-2021 (Mar-22-2021, 06:52 PM)Axel_Erfurt Wrote: They are not empty I see thank you, do you know a way to assign the days to two separate empty lists? RE: Lists + Empty Lists - Larz60+ - Mar-22-2021 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 >>> RE: Lists + Empty Lists - Pytho13 - Mar-22-2021 (Mar-22-2021, 06:59 PM)Larz60+ Wrote: Hint: 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 :( RE: Lists + Empty Lists - Pytho13 - Mar-22-2021 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 RE: Lists + Empty Lists - Axel_Erfurt - Mar-22-2021 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:] RE: Lists + Empty Lists - Pytho13 - Mar-22-2021 (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 ? 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. |