Added two optimized pythonic functions and removed unnecessary semicolons.#66
Open
rushil180101 wants to merge 3 commits intomarcosfede:masterfrom
Open
Added two optimized pythonic functions and removed unnecessary semicolons.#66rushil180101 wants to merge 3 commits intomarcosfede:masterfrom
rushil180101 wants to merge 3 commits intomarcosfede:masterfrom
Conversation
Used list comprehension to store alphanumeric characters. Then compared the original and the reversed list and returned the result of the comparison.
It uses inbuilt type conversions. Strings are converted to decimal representation, then the decimal numbers are added and the result is again converted to string. The required part of the resulting string is returned by the function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello, I have proposed the following changes to include optimized code and resemble pythonic syntax in the strings section.
Added function
is_palindrome_pythonic()instrings/is_palindrome.pyfile. Used list comprehension to store alphanumeric characters in a list, then compared it with its reverse (using the pythonic way) and finally return the result of the comparison.Added function
add_binary_pythonic()instrings/add_binary.pyfile.ais concatenated with a prefix'0b'. This string (e.g. '0b1101') represents binary number 1101 in python.'0b' + aint()function of python with second parameter as 2, which represents the base of the first parameter string (binary = base 2).int('0b' + a, 2)int()function converts the string (e.g. '0b1101') to the decimal value and stores in the variabledecimal_a. (e.g. '0b1101' converts to 13)decimal_a = int('0b' + a, 2)b.decimal_b = int('0b' + b, 2)bin()function.bin(decimal_a + decimal_b)'0b'(e.g. '0b10110'), which is sliced to keep the part after'0b'.[2:]Removed semicolons in
strings/int_to_roman.pyfile to resemble python syntax.Any suggestions and feedback are welcomed.