- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
Test6 #4
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
base: test5
Are you sure you want to change the base?
Test6 #4
Changes from all commits
1c76a8d
              715dc06
              260bf49
              285fb23
              3ade6da
              2d9854b
              ae34859
              a5a7698
              044e7d9
              d215cb3
              e2617e5
              da89f1a
              d2f998a
              8e614da
              fa8ef06
              3790345
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #!/usr/bin/python3 | ||
| 
     | 
||
| # Added for testing | ||
| # Added for testing line 2 | ||
| # Examples for dictionary | ||
| # Empty Dictionary | ||
| emp_dict = {} | ||
| 
     | 
||
| # dictionary with integer keys | ||
| emp_dict = {100: 'Sanjeev', 101: 'Jassi'} | ||
| print(emp_dict) | ||
| 
     | 
||
| # dictionary with mixed keys | ||
| emp_dict = {100: 'Sanjeev', 'skills': ['Python', 'AWS']} | ||
| print(emp_dict) | ||
| 
     | 
||
| # using dict() function | ||
| emp_dict = dict({100: 'Sanjeev', 101: 'Jassi'}) | ||
| print(emp_dict) | ||
| 
     | 
||
| # Let's create emp_dict of this format | ||
| ''' | ||
| { | ||
| 'Employee ID': | ||
| { Name: 'string' | ||
| Joined: 'yyyy-mm-dd' | ||
| Title: 'string' | ||
| Skills: [‘list’, ‘of’, ‘skills’] | ||
| Project: {‘project_name’: ‘project description’} | ||
| } | ||
| } | ||
| ''' | ||
| 
     | 
||
| # Initializing Employee | ||
| emp_dict = { | ||
| 100: | ||
| { | ||
| 'name': "Sanjeev", | ||
| 'joined': "2017-08-14", | ||
| 'title': "Cloud Security Engineer", | ||
| 'skills': ['Python', 'AWS', 'AppSec'], | ||
| 'projects': { | ||
| 'CSPM implementation': 'Implement Cloud Security Posture for AWS' | ||
| } | ||
| }, | ||
| 101: | ||
| { | ||
| 'name': "Jassi", | ||
| 'joined': "2017-10-27", | ||
| 'title': "Cloud Security Manager", | ||
| 'skills': ['Python', 'AWS', 'AWS Security'], | ||
| 'projects': { | ||
| 'CSPM implementation': 'Implement Cloud Security Posture for AWS and Azure' | ||
| } | ||
| } | ||
| } | ||
| 
     | 
||
| print(emp_dict) | ||
| 
     | 
||
| # Get the type of emp_dict | ||
| print(type(emp_dict)) | ||
| 
     | 
||
| # get keys of a dictionary using keys() | ||
| emp_ids = emp_dict.keys() | ||
| print(emp_ids) | ||
| 
     | 
||
| # Get values of a dictionary using values() | ||
| emp_details = emp_dict.values() | ||
| print(emp_details) | ||
| 
     | 
||
| # get key and value both using items() | ||
| emps = emp_dict.items() | ||
| print(emps) | ||
| 
     | 
||
| # Length of a dictionary (number of items) using len() | ||
| print(len(emp_dict)) | ||
| 
     | 
||
| # Iterate through a dictionary | ||
| for id in emp_dict.keys(): | ||
| print(f"Employee ID: {id}") | ||
| print(f"\tEmployee Details: {emp_dict[id]}") | ||
| 
     | 
||
| # Accessing elements from dictionary | ||
| # get vs [] for retrieving elements | ||
| # Sanjeev | ||
| print(emp_dict[100]['name']) | ||
| 
     | 
||
| # ['Python', 'AWS', 'AppSec'] | ||
| print(emp_dict[101].get('skills')) | ||
| 
     | 
||
| # Try to access keys which doesn't exist | ||
| # None | ||
| print(emp_dict[100].get('mailid')) | ||
| 
     | 
||
| try: | ||
| print(emp_dict[101]['location']) | ||
| except KeyError: | ||
| print("Location not found for employee 101") | ||
| 
     | 
||
| # Add one more employee to emp_dict using update() | ||
| new_emp = [{ | ||
| 102: | ||
| { | ||
| 'name': "Rakesh", | ||
| 'joined': "2018-01-07", | ||
| 'title': "Business Analyst", | ||
| 'skills': ['Power BI', 'MBA', 'Marketing Expert'], | ||
| 'projects': { | ||
| 'Flexmind Marketing': 'Increase the membership my targeted marketing' | ||
| } | ||
| } | ||
| }] | ||
| 
     | 
||
| emp_dict.update(new_emp) | ||
| print(emp_dict) | ||
| 
     | 
||
| # Update the existing value. Update title of emp_id: 100 as "Sr. Cloud Security Engineer" | ||
| emp_dict[100]['title'] = "Sr. Cloud Security Engineer" | ||
| print(emp_dict[100]) | ||
| 
     | 
||
| # Learn to delete | ||
| # pop, clear, del | ||
| # Pop employee id 101 | ||
| emp_dict.pop(101, "Not found") | ||
| print(len(emp_dict)) | ||
| 
     | 
||
| # Delete the employee 102 | ||
| del emp_dict[102] | ||
| print(len(emp_dict)) | ||
| 
     | 
||
| # Clear the dictionary | ||
| emp_dict.clear() | ||
| print(emp_dict) | ||
| 
     | 
||
| # Delete the dictionary itself and printing it would throw an error | ||
| del emp_dict | ||
| # print(emp_dict) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||||||||
| import re | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| urls = ["https://www.facebook.com","https://www.google.com","https://www.amazon.in"] | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| def checkValidURL(url): | ||||||||||||||||||||
| url_reg_ex = r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?" | ||||||||||||||||||||
| data = re.search(url_reg_ex,url) | ||||||||||||||||||||
| if data is not None: | ||||||||||||||||||||
| return True | ||||||||||||||||||||
| return False | ||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| def parseDomain(url): | ||||||||||||||||||||
| domain = url.split("//")[1].split("www")[1].split(".")[1] | ||||||||||||||||||||
| print(domain) | ||||||||||||||||||||
| 
         
      Comment on lines
    
      +12
     to 
      +14
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fragile URL parsing with chained splits 
The  Code suggestionCheck the AI-generated fix before applying 
        Suggested change
       
    
 Code Review Run #37b90a Should Bito avoid suggestions like this for future reviews? (Manage Rules) 
  | 
||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| 
     | 
||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||
| for url in urls: | ||||||||||||||||||||
| url_status = checkValidURL(url) | ||||||||||||||||||||
| if url_status: | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| parseDomain(url) | ||||||||||||||||||||
| except (ValueError, IndexError) as e: | ||||||||||||||||||||
| print(f"Error parsing domain for {url}: {e}") | ||||||||||||||||||||
| 
         
      Comment on lines
    
      +23
     to 
      +24
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing indentation in except block 
There's a syntax error on line 24 due to missing indentation in the  Code suggestionCheck the AI-generated fix before applying 
        Suggested change
       
    
 Code Review Run #b1d35b Should Bito avoid suggestions like this for future reviews? (Manage Rules) 
  | 
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1 +1,2 @@ | ||
| # Python-examples | ||
| # Python-examples | ||
| Utility functions and scripts | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
new_empvariable is incorrectly defined as a list containing a dictionary instead of just a dictionary. This will cause a TypeError when callingemp_dict.update(new_emp)sinceupdate()expects a dictionary, not a list.Code suggestion
Code Review Run #37b90a
Should Bito avoid suggestions like this for future reviews? (Manage Rules)