Posts

Showing posts with the label array

Date Format in python programming

Image
Problem:- Create a function that converts a date formatted as MM/DD/YYYY to YYYYDDMM. Examples:- format_date("11/12/2019") ➞ "20191211" format_date("12/31/2019") ➞ "20193112" format_date("01/15/2019") ➞ "20191501" Code:- Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Add the Index Python Programming

Image
Problem:- Given a list of numbers, create a function that returns the list but with each element's index in the list added to itself. This means you add 0 to the number at index 0, add 1 to the number at index 1, etc... Examples:- add_indexes([0, 0, 0, 0, 0]) ➞ [0, 1, 2, 3, 4] add_indexes([1, 2, 3, 4, 5]) ➞ [1, 3, 5, 7, 9] add_indexes([5, 4, 3, 2, 1]) ➞ [5, 5, 5, 5, 5] Code:-  Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Clone a List Python Programming

Image
Problem:- The Code tab has code that attempts to add a clone of a list to itself. There is no error message, but the results are not as intended. Can you fix the code? Examples:- clone([1, 1]) ➞ [1, 1, [1, 1]] clone([1, 2, 3]) ➞ [1, 2, 3, [1, 2, 3]] clone(["x", "y"]) ➞ ["x", "y", ["x", "y"]] Code:- Problem code. Answer code. Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.