Problem:- Write a function that moves all elements of one type to the end of the list. Examples:- move_to_end([1, 3, 2, 4, 4, 1], 1) ➞ [3, 2, 4, 4, 1, 1] # Move all the 1s to the end of the array. move_to_end([7, 8, 9, 1, 2, 3, 4], 9) ➞ [7, 8, 1, 2, 3, 4, 9] move_to_end(["a", "a", "a", "b"], "a") ➞ ["b", "a", "a", "a"] Code:- Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.
Problem:- Create a function that takes a string and returns a string with its letters in alphabetical order. Examples:- alphabet_soup("hello") ➞ "ehllo" alphabet_soup("edabit") ➞ "abdeit" alphabet_soup("hacker") ➞ "acehkr" alphabet_soup("geek") ➞ "eegk" alphabet_soup("javascript") ➞ "aacijprstv" Notes:- You can assume numbers and punctuation symbols won't be included in test cases. You'll only have to deal with a single word, alphabetic characters. Code:- (You can write direct one line code like : return "".join(sorted(txt)) Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.
Problem:- Create a function to calculate how many characters in total are needed to make up the shape. You will be given a list of strings that make up a shape in the compiler (i.e. a square, a rectangle, or a line). Examples:- count_characters([ "###", "###", "###" ]) ➞ 9 count_characters([ "22222222", "22222222", ]) ➞ 16 count_characters([ "------------------" ]) ➞ 18 count_characters([]) ➞ 0 count_characters(["", ""]) ➞ 0 Code:- Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.
Comments
Post a Comment