Back
Close

Sanbox Interview

lizzij
2,811 views

TEST_STRING = 'Hello World!!'

def count_vowels(given_string): VOWELS = ['a', 'e', 'i', 'o', 'u'] return len([letter for letter in given_string if letter.lower() in VOWELS]) print('Number of vowels in '%s' is %d' % (TEST_STRING, count_vowels(TEST_STRING)))

def count_alphabets(given_string): return len([letter for letter in given_string if letter.isalpha()]) print('Number of letters in '%s' is %d' % (TEST_STRING, count_alphabets(TEST_STRING)))

def keep_alphabets(given_string): return ''.join([letter for letter in given_string if letter.isalpha()]) print('All alphabets in '%s' are '%s'' % (TEST_STRING, keep_alphabets(TEST_STRING)))

def keep_first_occur_alphas(given_string): return ''.join(list(dict.fromkeys(keep_alphabets(given_string)).keys())) print('The first occurances of all letters in '%s' is '%s'' % (TEST_STRING, keep_first_occur_alphas(TEST_STRING)))

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io