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

Update utils.py #111

Closed
wants to merge 1 commit into from
Closed

Conversation

akshitbansal2005
Copy link

  1. What it Does: The function takes a dictionary (which could have nested dictionaries and lists inside it) and turns it into a readable, formatted string. It lets you choose which keys to ignore and adjusts indentation based on the depth of nesting.

  2. Handling Inputs:

    • It avoids issues with mutable defaults by setting ignore to an empty list if none is provided.
    • depth controls how much indentation each level gets, so deeper levels appear visually indented in the final string.
  3. Efficiency:

    • Instead of constantly building a single large string (which can be slow for large dictionaries), it collects lines in a list and joins them at the end, making the function faster.
  4. Handling Different Data Types:

    • Lists are formatted as comma-separated values.
    • Nested dictionaries are handled with recursion, making sure each nested level gets formatted properly without cluttering the main function.
  5. Readability Improvements:

    • It uses modern string formatting (f-strings) for clarity.
    • It leaves dictionary key capitalization as-is, giving the output a more natural look.

1. **What it Does**:  
   The function takes a dictionary (which could have nested dictionaries and lists inside it) and turns it into a readable, formatted string. It lets you choose which keys to ignore and adjusts indentation based on the depth of nesting.

2. **Handling Inputs**:
   - It avoids issues with mutable defaults by setting `ignore` to an empty list if none is provided.
   - `depth` controls how much indentation each level gets, so deeper levels appear visually indented in the final string.

3. **Efficiency**:
   - Instead of constantly building a single large string (which can be slow for large dictionaries), it collects lines in a list and joins them at the end, making the function faster.

4. **Handling Different Data Types**:
   - Lists are formatted as comma-separated values.
   - Nested dictionaries are handled with recursion, making sure each nested level gets formatted properly without cluttering the main function.

5. **Readability Improvements**:
   - It uses modern string formatting (f-strings) for clarity.
   - It leaves dictionary key capitalization as-is, giving the output a more natural look.
Copy link
Contributor

github-actions bot commented Nov 3, 2024

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. In the meantime, please ensure that your changes align with our chaotic CONTRIBUTING.md. If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

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.

1 participant