Day: February 22, 2021

Python Example – Write a Python program to check the priority of the four operators

Hits: 7 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to check the priority of the four operators (+, -, *, /). Sample Solution: Python Code: from collections import deque import re __operators__ = “+-/*” __parenthesis__ = “()” __priority__ = { ‘+’: 0, ‘-‘: 0, ‘*’: 1, ‘/’: 1, …

Python Example – Write a Python program to add two positive integers without using the ‘+’ operator

Hits: 8 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to add two positive integers without using the ‘+’ operator. Note: Use bitwise operations to add two numbers.   Sample Solution: Python Code: def add_without_plus_operator(a, b): while b != 0: data = a & b a = a ^ …

Python Example – Write a Python program to create all possible permutations from a given collection of distinct numbers

Hits: 4 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to create all possible permutations from a given collection of distinct numbers.   Sample Solution: Python Code: def permute(nums): result_perms = [[]] for n in nums: new_perms = [] for perm in result_perms: for i in range(len(perm)+1): new_perms.append(perm[:i] + …

Python Example – Write a Python program to check the sum of three elements (each from an array) from three arrays is equal to a target value

Hits: 4 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to check the sum of three elements (each from an array) from three arrays is equal to a target value. Print all those three-element combinations. Sample data: X = [10, 20, 20, 20] Y = [10, 20, 30, 40] …

Python Example – Write a Python program to get a list of locally installed Python modules

Hits: 5 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get a list of locally installed Python modules.   Sample Solution: Python Code: import pkg_resources installed_packages = pkg_resources.working_set installed_packages_list = sorted([“%s==%s” % (i.key, i.version) for i in installed_packages]) for m in installed_packages_list: print(m) Sample Output: asn1crypto==0.24.0 beautifulsoup4==4.5.1 biopython==1.71 …

Python Example – Write a Python program to get the top stories from Google news

Hits: 1 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get the top stories from Google news.   Sample Solution: Python Code : import bs4 from bs4 import BeautifulSoup as soup from urllib.request import urlopen news_url=”https://news.google.com/news/rss” Client=urlopen(news_url) xml_page=Client.read() Client.close() soup_page=soup(xml_page,”xml”) news_list=soup_page.findAll(“item”) for news in news_list: print(news.title.text) print(news.link.text) print(news.pubDate.text) …

Python Example – Write a Python program to count the number of each character of a text file

Hits: 2 (Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to count the number of each character of a text file. Inputs: abc.txt German Unity Day From Wikipedia, the free encyclopedia The Day of German Unity (German: Tag der DeutschenEinheit) is the national day of Germany, celebrated on 3 …