Yet another thread showing how awful I am at programming...

I've got a list called week_pattern

It contains a list of 52-character strings which represent whether something occurs in a certain week. The list is below:

['0000000000111111111100000000000000000000000000000000', '0000000001000000000000000000000000000000000000000000', '0000000000000000000000000011111111000011100000000000', '0000000000000101111100000000000000000000000000000000', '0000000001111111111100000000000000000000000000000000', '0000000000111111111100000000000000000000000000000000', '0000000000000000000000000001111111000001100000000000', '0000000000111000000000000000000000000000000000000000', '0000000001111111111100000000000000000000000000000000', '0000000000000000000000000011111111000011100000000000', '0000000000000000000000000011111111000011100000000000', '0000000000000111111100000000000000000000000000000000', '0000000000000000000000000000000000000000001000000000', '0000000000000000000000000001111111000001100000000000', '0000000000000000101000000000000000000000000000000000', '0000000000000000000000000000000000000001000000000000', '0000000001111111111100000000000000000000000000000000']

As you can see, the number 0's mean that there is nothing happening and the number 1's mean that something is happening in those weeks. Here there are 17 strings relating to 17 subjects..

How would I go about assigning them weeks? What i've thought about is this:

0 = false
1 = true

for all 0's, assign false
for all 1's, check the index against a reference list containing the start date of the week

Problem is checking each individual one and zero, as opposed to a big 52-character integer.

4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by Xzarik

Seems fun but I don't understand.

Can you explain?

Cheers and Happy coding

In the timetabling software my university uses, the year is represented by a 52 character list.

By default all these weeks are 0, however if a lecture is scheduled in this week then they get a value of 1.

I need to somehow convert this data into an actual date format. I know what day of the week the activities are on, but need to combine that with the week pattern to get an actual date.

I think if I have a reference list which reads as follows:

1, 27/07/2009, 28/07/2009, 29/07/2009, 30/07/2009, 31/07/2009
2, 03/08/2009, 04/08/2009, 05/08/2009, 06/08/2009, 07/08/2009
3, 10/08/2009, 11/08/2009, 12/08/2009, 13/08/2009, 14/08/2009
4, 17/08/2009, 18/08/2009, 19/08/2009, 20/08/2009, 21/08/2009
etc

Then a string of:

0010

Will bring the result:

3, 10/08/2009, 11/08/2009, 12/08/2009, 13/08/2009, 14/08/2009

From there I reckon if I assign MON, TUES, WED, THURS and FRI values from 1-5 then if the activity is on a THURS it'll grab the 13/08/2009 value from that list.

Is it doable?

Sorry if I didn't explain it very well, it's unnecessarily complicated!

Well, first of all the True and False boolean values already exist in Python. Second, strings are immutable in Python. This means they cannot be changed.
You could on the other hand do something like this:

for i in range(len(someList)):
if someList[i].count('0') > someList[i].count('1'):
someList[i] = False
else:
someList[i] = True

where someList is your list of what appear to be strings containing binary.
This would cycle through the elements in the list, and compare the number of times the "0" character appears as opposed to "1". If there are more 0s, replace that binary string with False. Otherwise, replace it with True. You could change this to meet your needs quite easily.

Something like this should help ...

active_days = [
[1, '27/07/2009', '28/07/2009', '29/07/2009', '30/07/2009', '31/07/2009'],
[2, '03/08/2009', '04/08/2009', '05/08/2009', '06/08/2009', '07/08/2009'],
[3, '10/08/2009', '11/08/2009', '12/08/2009', '13/08/2009', '14/08/2009'],
[4, '17/08/2009', '18/08/2009', '19/08/2009', '20/08/2009', '21/08/2009']
]

active_weeks= '0010'
for ix, week in enumerate(active_weeks):
if week == '1':
print(active_days[ix])

""" result >>>
[3, '10/08/2009', '11/08/2009', '12/08/2009', '13/08/2009', '14/08/2009']
"""

The Python module calendar should be of great help too!

Oh wow that's really good, why didn't I think of it that way?! That's so much simpler and also easier to understand than the way I was thinking about it...

So what i've got now is i've imported the reference sheet containing all 52 weeks, and have imported the weeks into another list:

active_weeks = ['0000000000111111111100000000000000000000000000000000', '0000000001000000000000000000000000000000000000000000', '0000000000000000000000000011111111000011100000000000', '0000000000000101111100000000000000000000000000000000', '0000000001111111111100000000000000000000000000000000', '0000000000111111111100000000000000000000000000000000', '0000000000000000000000000001111111000001100000000000', '0000000000111000000000000000000000000000000000000000', '0000000001111111111100000000000000000000000000000000', '0000000000000000000000000011111111000011100000000000', '0000000000000000000000000011111111000011100000000000', '0000000000000111111100000000000000000000000000000000', '0000000000000000000000000000000000000000001000000000', '0000000000000000000000000001111111000001100000000000', '0000000000000000101000000000000000000000000000000000', '0000000000000000000000000000000000000001000000000000', '0000000001111111111100000000000000000000000000000000']

I've tried:

for line in active_weeks:

But to no avail... =/ Any clues?

# I assume you have created the total active_days_list

active_weeks_list = [
'0000000000111111111100000000000000000000000000000000',
'0000000001000000000000000000000000000000000000000000',
'0000000000000000000000000011111111000011100000000000',
'0000000000000101111100000000000000000000000000000000',
'0000000001111111111100000000000000000000000000000000',
'0000000000111111111100000000000000000000000000000000',
'0000000000000000000000000001111111000001100000000000',
'0000000000111000000000000000000000000000000000000000',
'0000000001111111111100000000000000000000000000000000',
'0000000000000000000000000011111111000011100000000000',
'0000000000000000000000000011111111000011100000000000',
'0000000000000111111100000000000000000000000000000000',
'0000000000000000000000000000000000000000001000000000',
'0000000000000000000000000001111111000001100000000000',
'0000000000000000101000000000000000000000000000000000',
'0000000000000000000000000000000000000001000000000000',
'0000000001111111111100000000000000000000000000000000'
]

for active_weeks in active_weeks_list:
for ix, week in enumerate(active_weeks):
if week == '1':
print(active_days_list[ix])

You, sir, are a lifesaver.

For some reason that only works with a "break" tagged on to the end - it does it all twice otherwise =/

But I can definitely live with that! Thank you so much =)