Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerRank Capitalize! problem solution in Python

YASH PAL, 31 July 2024

In this HackerRank Capitalize problem solution in python, You are asked to ensure that the first and last names of people begin with a capital letter in their passports. 

Given a full name, your task is to capitalize the name appropriately.

HackerRank Capitalize! solution in Python

Problem solution in Python 2 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
import string

words = raw_input().split(' ')
for i in xrange(len(words)):
    words[i] = string.capitalize(words[i])

print ' '.join(words)

Problem solution in Python 3 programming.

# Complete the solve function below.
def solve(s):
    for x in s[:].split():
        s = s.replace(x, x.capitalize())
    return s

Problem solution in pypy programming.

def capitalize(string):
    os=""
    for idx,x in enumerate(string):
        #print (x,idx,str1[idx-1])
        os+=x.upper() if string[idx-1]==" " or idx == 0 else x
    return "".join(os)

Problem solution in pypy3 programming.

def capitalize(string):
    s=""
    space=True
    for x in string :
        if space and x!=' ':
            s=s+x.upper() 
            space=False
        elif x==' ':
            s=s+x
            space=True
        else :
            s=s+x
                    
    return s 

coding problems solutions Hackerrank Problems Solutions Python Solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes