Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(Re)Build String to MultiValue Hash
#!/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
You can’t perform that action at this time.