rh-openstack-ci-team
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Python questions for interviews ## Easy ### Question 1 Can you tell the difference between unit, functional, and integration tests ? Functional testing is defined as the testing of complete functionality of some application. Integration tests, test how parts of the system work together and unit tests test the small pieces of the application. Comments ### Question 2 Given the following list: ``` words = ["one", "one", "two", "three", "three", "two"] ``` how can you display only the unique elements of the array Possible answer: ``` list(set(words)) ``` ### Question 3 What’s a list comprehension ? ### Question 4 What's the difference between: ``` x = [i for i in range(10)] ``` and ``` x = (i for i in range(10)) ``` One create a list with 10 elements starting in 0, the other create an iterator ### Question 5 Which one is better, and why use one or another Iterator is used when you only need to calculate the next value in real time, it's faster depending on what is inside the list, the list has all the elements. Iterator is also fixed values in memory while lists increase depending on the number of elements. ### Question 6 What __getattr__ do? ### Question 7 What is a decorator in python ### Question 8 I have a function in python that download a very large glance image calculates the md5sum and return it, what's the best way to test this function without need to download the image ``` Using Mock ``` ### Question 9 What are local variables and global variables in Python? Global Variables: Variables declared outside a function or in global space are called global variables. These variables can be accessed by any function in the program. Local Variables: Any variable declared inside a function is known as a local variable. This variable is present in the local space and not in the global space. ### Question 10 What is the difference between Python Arrays and lists? Arrays and lists, in Python, have the same way of storing data. But, arrays can hold only a single data type elements whereas lists can hold any data type elements. ### Question 11 What is monkey patching? Dynamic modifications of a class or module at run-time refers to a monkey patch. ## Medium / Advanced ### Question 1 How do you sort a Python Snake sequence when the ordered is induced by *another* sequence? (For example, how do you sort a list of names by the age of each person?) Example ``` names = ["A", "B", "C", "D"] ages = [21, 35, 18, 78] ``` Answer ``` sorted(zip(ages, names)) ``` ``` ordered_names = [name for _, name in sorted(zip(ages, names))] ordered_names ``` ### Question 2 (tricky) You have the following: ``` names = ["A", "B", "C", None] ages = [20, 30, 40, 20] ``` What's the output of this: ``` (23, "A") < (20, None) False (19, "A") < (20, None) True (20, "A") < 20, None) TypeError exception ``` What would happen if you sort it with zip? ``` sorted(zip(ages, names)) TypeError exception ``` ### Question 3 (tricky) What's the output of this code: ``` a = 3 l = [3, 5] if a in l == True: print("Yeah") else: print("What?") ``` Explanation: `in` is a comparison operator, meaning the expression corresponds to 2 comparisons that have been chained, much like `2 < 4 < 7`is `2 < 4 and 4 < 7`. ## Hard (but easy) ### Question 1 How can you calculate the triangular number? For example, the triangular number for 3 is 6: ``` # * # * * # * * * ``` Possible sollution ``` def triangular_number(n): acc = 0 for i in range(n + 1): acc += i return acc ``` Better sollution ``` def triangular_number(n): return sum(range(n + 1)) ``` However, this is a linear function, this can be better: ``` def triangular_number(n): if n == 1: return 1 return n + triangular_number(n - 1) ``` But what's the issue with this? ``` triangular_number(1023) ``` ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 4, in triangular_number File "<stdin>", line 4, in triangular_number File "<stdin>", line 4, in triangular_number [Previous line repeated 995 more times] File "<stdin>", line 2, in triangular_number RecursionError: maximum recursion depth exceeded in comparison ``` The sum of 1 + 2 + ... + N can be simplified to N * (N + 1) / 2: ``` def triangular_number(n): return n * (n + 1) / 2 ``` But the output now is a float: ``` >>> triangular_number(10_000_000) 50000005000000.0 ``` Resolving casting int: ``` def triangular_number(n): return int(n * (n + 1) / 2) ``` Tends to rounding errors: ``` >>> triangular_number(10_000_000_000) 50000000005000003584 ``` What's the sollution then? Use //: ``` def triangular_number(n): return n * (n + 1) // 2 ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully