Monday, May 29, 2023

Find longest name on a list and add white spaces

 The requirement here is the find the longest name in a list of names and prepend the names with certain length of white spaces


## Find longest name...
names = ["GAJERE VINCENT", "BASHIRU SAHEED OLAMIDE", "IBRAHIM ABUBAKAR ISAH", "AL-HASSAN MUSA ABDULRAHMAN", "OGWUCHE OGBENE VICTORIA", "RAIMI RAFATU AMINAT", "OGBONNA NKWADOCHUKWU VICTORY", "JOB SHIGABA TASHILANI", "ABANG OCHIBE TREASURE", "ANDREW JOSHUA ", "AMEH JOHN OYOCHE", "PHILIP SAMSON ", "SALIHU AWWAL", "DANLADI VICTOR KARSHI", "IBRAHIM FARIDA JIBRIN", "HUSSEIN ONYIOZA AMINAT", "BITRUS JOSEPH ", "YAHAYA ABDULBASID", "MAIKUDI OLLO MIRACLE", "ADEYI SAMSON DIEGO", "BENJAMIN TAGWAI THANKGOD", "EDEGO JAMES EYA", "ABDULMANAN OMEIZA NURUDEEN", "YAHAYA OVAYOZA UMMULKULSUM", "ALKALI UMAR ", "UMAR RABIYAH", "SALUHU SULEIMAN MUHAMMED", "UMAR MUHAMMAD SADAUKI", "OWOICHO INALEGWU SOLOMON", "HUSSAINI FARIDAH OYIEZA", "SUNDAY DANIEL ", "ALKALI ABIMIKU AKPOMOSHI", "JOSEPH MFON RUTH", "EDOR EYARE BLESSING", "IBRAHIM UMAR", "TAR PHILIP ORJIME", "XXX", "KACHALA ANGELA EWA", "ADAMU MARYAM", "YAKUBU OJOMAH RASHIDA", "IORUMBUR ANGEL TERKUMBUR", "IDOKO IRENE OLUCHUKWU", "ADEGOKE QUEEN BISOLA", "TIJANI ABDULMUMIN MARYAM", "NWODO ONYEDIKA DANIEL", "ALFRED EKOSA JOY", "AYOGU CHIDIEBERE BENARD", "IDRIS ISMAIL UMMULKULSUM", "ADUKWU ENE JANET", "MUHAMMED AGBO FATIMA", "MAIKEFFI JOB ", "SAMUEL SHEKWOYEMILO CHRISTIANA", "SAMUEL OSHULEYI", "KYAUTA BOAZ CHONGFI", "QASIM ALIYU ABUBAKAR", "ABANKWA MARIA ORESI", "ABDULLAHI AMINAT OSHEIZA", "IBRAHIM OMEIZA HUSSEIN", "AHMED OMAYIOZA SHERIFAT", "XXX", "AKANKANEE GIFT GODWIN", "ADOGA ATAMPA ATIKU", "ABDULLAHI ADINOYI ABDULBAKI", "GABRIEL ADEOLA REBECCA", "ELKANAH KADALAH JOSHUA", "ISHAQ YAHAYA", "MBASEN SARAH ANGULA", "YUSUF HALIMA", "JAMES MBACHA ", "KANTIOK FELIX ", "BRIGHT OGBENETEGA LUCKY", "PATRICK ORUW MIRACLE", "NICODEMUS RITA ", "ABDULWAHEED ASIYAT ", "MUSA RAFAT ALABA", "JATTO ADEIZA JAMIU", "YAKUBU OLAGOKE ABDULAZEEM", "ADANU PAUL ", "HASSAN KUZHIAGYE GAZA", "HARUNA MUHAMMED NASIRU", "VINCENT EXCELLENT ", "UGWU NMESOMA JESSICA", "JAMES GODWIN", "WILLIAMS LEBO MICHAEL", "OKWOR MARY-CYNTHIA CHIAMAKA", "JOSEPH MINTON HAPPINESS", "EDEANI KOSISOCHUKWU FAVOUR", "ASUVA ADEIZA KASHIM", "NASIRU MULIKAT", "JACOB MARY ", "SOKOKAYE KINSOKO WISDOM", "NWAFOR FAITH CHIDIMMA", "USMAN CHENEMI MERCY", "JEFF FAVOUR DIVINE", "NKWAZEMA IFESINACHI EDWARD", "YAKUBU HUSSEINA", "AKPENNONGON EMMANUEL ORSEER", "YAKUBU JULIUS PIUS", "SODIQ ADAVIZE MAHMUD", "OTACHE HASSAN SULEIMAN", "ABUH HAUWAKULU SANI", "DAVID FAVOUR ", "ABANG NJONG FAVOUR", "SAMUEL SABASTINE MAGODE", "SIMON BEGNASHEBWANA ELISHA", "SULEIMAN KHADIJAT OMOTOLA", "IORWASHIMA MNGUSUUR WINIFRED", "MUHAMMED ABIGE ABDULMALIK", "TOOR FAVOUR MNGUSUUR", "SYLVANUS NENDRIMWA JUDITH", "PATRICK GRACE WANDOO", "KWAV MEMBER GRACE", "EDWARD FRANCIS OWOGOGA", "EMMANUEL FAVOUR AKOCHE", "YONGBA MATTHEW AONDOUNGWA", "OCHI NGBEDE INNOCENT", "EMMANUEL LAMOSI TESTIMONY", "THOMAS JOEL NPEKNOM", ]
print(len(names))

len_name_list = []
for a in names:
    len_name_list.append(len(a))

uniq_len_name = list(set(len_name_list))
print(f'{uniq_len_name[-1]} characters is the Longest name on the list...')


# Add trailing spaces...
for a in names:
    print(a.ljust(uniq_len_name[-1]+5, ' '))




Happy coding!

No comments:

Post a Comment