Sanbox Interview

lizzij
1,156 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

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)))

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content