Skip to content

Instantly share code, notes, and snippets.

@mrcrnkovich
Last active September 4, 2019 16:10
Show Gist options
  • Select an option

  • Save mrcrnkovich/c0f81baa1653ce6a331714eece3cec0c to your computer and use it in GitHub Desktop.

Select an option

Save mrcrnkovich/c0f81baa1653ce6a331714eece3cec0c to your computer and use it in GitHub Desktop.
Codewars kata: Calculate mean and concatenate string
"""
Return an array of length 2 with a[0] representing the mean of the ten integers as a floating point number.
There will always be 10 integers and 10 characters. Create a single string with the characters and
return it as a[1] while maintaining the original order.
"""
def mean(lst):
#split list into integers and strings
lst_mean = [int(i) for i in lst if i.isdigit()]
lst_str = list(filter(lambda x: not x.isdigit(), lst))
#return arr[float, str]
return [sum(lst_mean)/len(lst_mean), ''.join(lst_str)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment