HackerRank Python Solution - Strings - Alphabet Rangoli

  • You are given an integer, N. Your task is to print an alphabet rangoli of size N. (Rangoli is a form of Indian folk art based on the creation of patterns.)
  • Different sizes of alphabet rangoli are shown below:

#size 3

----c----
--c-b-c--
c-b-a-b-c
--c-b-c--
----c----

HackerRank Python Solution - Strings - String Formatting

Given an integer, n, print the following values for each integer i from 1 to n:
  • Decimal
  • Octal
  • Hexadecimal (capitalized)
  • Binary
Function Description:
  • Complete the print_formatted function in the editor below.
  • print_formatted has the following parameters:
    • int number: the maximum value to print

HackerRank Python Solution - Strings - Capitalize!

  • You are asked to ensure that the first and last names of people begin with a capital letter in their passports. For example, alison heck should be capitalized correctly as Alison Heck.
HackerRank Python Solution - Strings - Capitalize!
  • Given a full name, your task is to capitalize the name appropriately.

HackerRank Python Solution - Strings - Text Wrap

  • You are given a string S and width w.
  • Your task is to wrap the string into a paragraph of width w.
Function Description:
  • Complete the wrap function in the editor below.
  • the wrap has the following parameters:
    • string: a long string
    • int max_width: the width to wrap to
    • Returns string: a single string with newline characters ('\n') where the breaks should be

HackerRank Python Solution - Strings - Text Alignment

  • In Python, a string of text can be aligned left, right and center.
.ljust(width):
  • This method returns a left-aligned string of length width.
>>> width = 20
>>> print 'HackerRank'.ljust(width,'-')
HackerRank----------

HackerRank Python Solution - Strings - String Validators

  • Python has built-in string validation methods for basic data. It can check if a string is composed of alphabetical characters, alphanumeric characters, digits, etc.
str.isalnum():
  • This method checks if all the characters of a string are alphanumeric (a-z, A-Z and 0-9).
>>> print 'ab123'.isalnum()
True
>>> print 'ab123#'.isalnum()
False

HackerRank Python Solution - Strings - Find a String

  • 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.
  • NOTE: String letters are case-sensitive.
Input Format:
  • The first line of input contains the original string. The next line contains the substring.

HackerRank Python Solution - Strings - Mutations

  • We have seen that lists are mutable (they can be changed), and tuples are immutable (they cannot be changed).
  • Let's try to understand this with an example.
  • You are given an immutable string, and you want to make changes to it.
Example:

>>> string = "abracadabra"

HackerRank Python Solution - Strings - What's Your Name?

You are given the firstname and lastname of a person on two different lines. Your task is to read them and print the following:
 
Hello firstname lastname! You just delved into python.
Function Description:
  • Complete the print_full_name function in the editor below.
  • print_full_name has the following parameters:
    • string first: the first name
    • string last: the last name
    • Prints string: 'Hello firstname lastname! You just delved into python' where and are replaced with first and last.

HackerRank Python Solution - Strings - Split and Join

In Python, a string can be split on a delimiter.

Example:

>>> a = "this is a string"
>>> a = a.split(" ") # a is converted to a list of strings. 
>>> print a
['this', 'is', 'a', 'string']
Joining a string is simple:
 
>>> a = "-".join(a)
>>> print a
this-is-a-string 

HackerRank Python Solution - Strings - sWAP cASE

You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.

For Example:

Www.HackerRank.com → wWW.hACKERrANK.COM
Pythonist 2 → pYTHONIST 2  

You might also like

Deploy your Django web app to Azure Web App using App Service - F1 free plan

In this post, we will look at how we can deploy our Django app using the Microsoft Azure app service - a free plan. You need an Azure accoun...