Skip to content
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

Bottom to top approach for list comprehension #815

Closed
vkosuri opened this issue Jul 2, 2017 · 2 comments
Closed

Bottom to top approach for list comprehension #815

vkosuri opened this issue Jul 2, 2017 · 2 comments

Comments

@vkosuri
Copy link
Collaborator

vkosuri commented Jul 2, 2017

With Referencing pull request comment #809 (comment)

Yes, I agree with @gunthercox comment, readability 👀 is very important it will gives us many advantages for example

  • Catching issues will be very easier and new develop/integration will become very easier.
  • Etc.

Yes sometime it is necessary to pick response also, With some hacks the below formats are looking good to me, the method i named it here ⤴️ Bottom to top approach for list comprehension, will provide more readability 👀

I did some exercise on some examples, please provide your comments/suggestion on this.

# Find the closest matching known statement
for statement in statement_list:
    confidence = self.compare_statements(input_statement, statement)

    if confidence > closest_match.confidence:
        statement.confidence = confidence
        closest_match = statement

vs

# The bottom to top approach for list comprehension, gives more readability
closest_match_and_confidence = [
    [
        statement,
        self.compare_statements(input_statement, statement)
    ] for statement in statement_list
]

Some more examples

for statement in statement_list:
    for response in statement.in_response_to:
        responses.add(response.text)

vs

# The bottom down approach for list comprehension, gives more readability
[
    responses.add(response.text)
    for statement in statement_list
    for response in statement.in_response_to
]

If it is looks good I'll try to make a PR which discussed here #738

@vkosuri vkosuri changed the title Bottom down approach for list comprehension Bottom to top approach for list comprehension 👀 Jul 2, 2017
@vkosuri vkosuri changed the title Bottom to top approach for list comprehension 👀 Bottom to top approach for list comprehension Jul 2, 2017
@gunthercox
Copy link
Owner

@vkosuri I agree that this formatting does improve the readability of the list comprehension. Feel free to create a pull request. 👍

@lock
Copy link

lock bot commented Mar 10, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants