Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Modify incorrect definition of str.capitalize() #1635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2023

Conversation

faze-geek
Copy link
Contributor

str.capitalize() in python should not only raise the first character to UpperCase but also necessarily converts all other characters to Lowercase.

Checkout master -

def f():
    x:str = "PyTHoN"
    print("PyTHoN".capitalize())
    print(x.capitalize())
    s:str = x.capitalize()
    print(s)

f()

(lp) faze-geek@DESKTOP-497JDCU:~/lpython/lpython$ python try.py
Python
Python
Python

(lp) faze-geek@DESKTOP-497JDCU:~/lpython/lpython$ ./src/bin/lpython try.py
PyTHoN
PyTHoN
PyTHoN

On branch -

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
Python
Python
Python

@faze-geek
Copy link
Contributor Author

I tested out this comment by to fix conflicts. Works perfectly and avoids use of git reset --hard. Thanks for that!

@faze-geek
Copy link
Contributor Author

@Thirumalai-Shaktivel Can you have a look at this once the CI logs run completely ? Thanks.

@czgdp1807 czgdp1807 marked this pull request as draft March 28, 2023 04:54
@faze-geek
Copy link
Contributor Author

This pull request is ready for review. @Shaikh-Ubaid

@faze-geek faze-geek marked this pull request as ready for review March 28, 2023 05:45
val = ord(x[0])
if val >= ord('a') and val <= ord('x'):
val = ord(res[0])
if val >= ord('a') and val <= ord('z'):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 681: Since we already know the ord() value for a and z, how about we directly use it as a constant value here? For example: if val >= 97 and val <= 122: # Check if lowercase.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using ord('a') is more readable.

Copy link
Collaborator

@ubaidsk ubaidsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shared a minor query above. It looks good to me. Thank you so much for this!

@certik certik merged commit 742c726 into lcompilers:main Mar 28, 2023
@faze-geek
Copy link
Contributor Author

Thanks @Shaikh-Ubaid and @certik for the set of reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants