Created
July 3, 2013 16:14
-
-
Save micalexander/5919949 to your computer and use it in GitHub Desktop.
python:Takes multiple strings and serializes it for php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/python | |
| weeks = [ | |
| ('Monday','Tuesday','Wednesday','Thursday','Friday'), | |
| ('Monday','Tuesday','Wednesday','Thursday','Friday'), | |
| ('Monday','Tuesday','Wednesday','Friday'), | |
| ('Monday','Tuesday','Wednesday','Thursday','Friday'), | |
| ('Monday','Tuesday','Wednesday','Thursday','Friday'), | |
| ('Monday','Tuesday','Wednesday','Thursday','Friday'), | |
| ('Monday','Tuesday','Wednesday','Thursday','Friday'), | |
| ('Monday','Tuesday','Wednesday','Thursday','Friday'), | |
| ('Monday','Tuesday','Wednesday','Thursday','Friday'), | |
| ('Monday','Tuesday','Wednesday','Thursday','Friday') | |
| ] | |
| serialized_weeks = [] | |
| for week in weeks: | |
| pre_string = 'a:'+str(len(week))+':{' | |
| for (i, string) in enumerate(week): | |
| pre_string += 'i:'+ str(i) + ';s:' + str(len(string)) + ':"' + string + '";' | |
| pre_string += '}' | |
| serialized_weeks.append(pre_string) | |
| for item in serialized_weeks: | |
| print item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment