Created
May 7, 2012 01:03
-
-
Save jbowles/2625242 to your computer and use it in GitHub Desktop.
(Re)Build String to MultiValue Hash
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/env python | |
def builder(string1,string2): | |
return string1 + ' ' + string2 | |
def insert(string_list): | |
return [char +'-' for char in string_list] | |
def joiner(string_list): | |
return ''.join(x for x in string_list) | |
def list_strip(string_list): | |
return ''.join([x.strip('-') for x in string_list]) | |
def multivalue_hash(string,hash_name,key_name): | |
return hash_name.setdefault(str(key_name), []).append(string.split(' ')) | |
#################### | |
s = "string" | |
t = "another string here" | |
print str("This is string1: " + s) | |
print str("This is string2: " + t) | |
string_list_built = builder(s,t) | |
print str("\n Concatenate two strings:\n"), string_list_built | |
inserted = insert(string_list_built) | |
print str("\n Insert '-' between every character:\n"), inserted | |
joined = joiner(inserted) | |
print str("\n Join all characters\n"), joined | |
final_result = list_strip(joined) | |
print str("\n Strip out all '-' between all characters\n"), final_result | |
mv_dict = {} | |
mv_dict.setdefault("strings", []).append(final_result.split(' ')) | |
print str("\n Create a multivalue hash with the string\n"), mv_dict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment