Posts

Showing posts with the label Python

Python Problem Solving - Lonely Integer

Given an array of integers, where all elements but one occur twice, find the unique element. Solution: n  =  int ( input ()) array  =  list ( map ( int ,   input () . rstrip () . split ())) for   element   in   array :      count  =  array . count ( element )      if   count  ==  1 :          print ( element )

Python-HackerRank-String Formatting

def   print_formatted ( number ):      results  =  []      for   i   in   range ( 1 ,   n + 1 ):          decimal  =  str ( i )          octal  =  str ( oct ( i )[ 2 :])          hex_  =  str ( hex ( i )[ 2 :]) . upper ()          binary  =  str ( bin ( i )[ 2 :])          results . append ([ decimal ,   octal ,   hex_ ,   binary ])      # print(results)      width  =  len ( results [ -1 ][ 3 ])        # print(width) # largest binary number      for   i   in   results :          print (...

HackerRank Python Problem - String Validators

HackerRank Python Problem: Question: You are given a string S. Your task is to find out if the string S contains: alphanumeric characters, alphabetical characters, digits, lowercase and uppercase characters .  Solution: if  __ name__  ==  '__main__' :      s  =  input ()      print ( any ( i . isalnum ()   for   i   in   s ))      print ( any ( i . isalpha ()   for   i   in   s ))      print ( any ( i . isdigit ()   for   i   in   s ))      print ( any ( i . islower ()   for   i   in   s ))      print ( any ( i . isupper ()   for   i   in   s ))

HackerRank Problem - Python

 HackerRank Python Problem: Question: In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left. Solution: def   count_substring ( string ,   sub_string ):      count  =  0      for   i   in   range ( len ( string )):          if   string [ i :] . startswith ( sub_string ):                  count  +=  1      return   count if  __ name__  ==  '__main__' :      string  =  input () . strip ()      sub_string  =  input () . strip ()           count  =  count_subst...

Python Syntax, Comments, Variables, Indentation

Execute Python Syntax As we learned in the past page, Python grammar can be executed by composing straightforwardly in the Command Line: >>> print("Hello, World!") Hello, World!  Or on the other hand by making a python record on the server, utilizing the .py document augmentation, and running it in the Command Line: C:\Users\ Your Name >python myfile.py  Python Indentation Space alludes to the spaces toward the start of a code line. Where in other programming dialects the space in code is for lucidness just, the space in Python is vital. Python utilizes space to show a square of code. if 5 > 2 :   print ( "Five is greater than two!" )   Python Variables In Python, factors are made when you relegate a worth to it: x = 5 y = "Hello, World!"   Python has no order for proclaiming a variable. Comments Python has remarking capacity with the end goal of in-code documentation. Remarks start with a #, and Python will deliver the remainder ...

Introduction to Python Programming

  Python is a well known programming language. It was made by Guido van Rossum, and delivered in 1991. It is utilized for:     web advancement (server-side),     programming advancement,     arithmetic,     framework prearranging. What else is there to do?     Python can be utilized on a server to make web applications.     Python can be utilized close by programming to make work processes.     Python can associate with information base frameworks. It can likewise peruse and alter documents.     Python can be utilized to deal with large information and perform complex arithmetic.     Python can be utilized for fast prototyping, or for creation prepared programming advancement. Why Python?     Python chips away at various stages (Windows, Mac, Linux, Raspberry Pi, and so on)     Python has a basic grammar like the Englis...

Python Problem- Find the Runner Up Score!!!

Problem Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given scores. Store them in a list and find the score of the runner-up.   Source Code n =  int ( input ()) list1 =  list ( map ( int , input () .strip () .split ()))[: n ] list2 =  list ( set ( list1 )) list2.sort ( reverse =  True ) x = list2 [ 1 ] print ( x )

Python-HackerRank Problem List Comprehensions

Problem Print a list of all possible coordinates given by (i,j,k) on a 3D grid where the sum of i+j+k is not equal to  n. Here, 0<=i<=x;0<=j<=y;0<=k<=z. Please use list comprehensions rather than multiple loops, as a learning exercise.  Source Code   if  __name__ ==  '__main__' :     x =  int ( input ())     y =  int ( input ())     z =  int ( input ())     n =  int ( input ())      print   ([[ a , b , c ]   for  a  in   range ( 0 , x+1 )   for  b  in   range ( 0 , y+1 )   for  c  in   range ( 0 , z+1 )     if  a + b + c != n  ])                 

WEB SCRAPING

 WEB SCRAPING Web scraping is Data Scraping used for extracting data from websites. It is also known as Web harvesting, Web data Extraction. It is basically copying where specific data is gathered and copied from the web, to a database or a spreadsheet for Data Analysis. Web scraping a web page involves fetching it and extracting from it. Fetching is the downloading of a page (which a browser does when a user views a page). Therefore, web crawling is a main component of web scraping, to fetch pages for later processing. Once fetched, then extraction can take place.The content of a page may be parsed, searched, reformatted, its data copied into a spreadsheet or loaded into a database. Web scrapers typically take something out of a page, to make use of it for another purpose somewhere else. An example would be to find and copy names and telephone numbers, or companies and their URLs, or e-mail addresses to a list (contact scraping). Click here to go through the example of We...