Skip to main content

Posts

Showing posts with the label python

Python Quizzes for Job Interview Preparation

Sample of Python Quizzes and Questions for Job Interview I'm doing some revision on python programming. May this helps you as well. Please try to understand the logic ya after seeing the code answer. Image by Shahid Abdullah from Pixabay Data Structure Quiz Implement a group_by_owners function that: Accepts a dictionary containing the file owner name for each file name. Returns a dictionary containing a list of file names for each owner name, in any order. For example, for dictionary {'Input.txt': 'Randy', 'Code.py': 'Stan', 'Output.txt': 'Randy'} the group_by_owners function should return {'Randy': ['Input.txt', 'Output.txt'], 'Stan': ['Code.py']} . My code answer Result : defaultdict( , {'Randy': ['Input.txt', 'Output.txt'], 'Stan': ['Code.py']})  Some additional info : A defaultdict works exactly like a normal dict, but it ...

Python regex finditer

Just a revision for me, sharing with you all! so i have problem to find multiple keywords in a text. i tried using re.search. but that wouldnt work. as re.search only applicable if keyword found first in a group match. so, lets go ahead! i ran using python2.7 Example code for find keywords appearance using python re.finditer (regex) search_keywords = ["smart", "high", "confident", "mature"]  Now we join the keywords with OR operator | , it will looks something like this  smart|high|confident|mature search_patterns = "|".join(search_keywords) Sample input text text = "This is a story about a girl. Living in a secluded area in Wonderland.\n" \        "She is small but very smart and smart, how ever she has verly low confident. Dont judge a book" \        "by its cover.\n The way she thinks shown how mature she is."  Now we update the pattern again with ( ) - > parenthesis  The object ...