Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python get first letter of string

import re

def first_letter(s):
    m = re.search(r'[a-z]', s, re.I)
    if m is not None:
        return m.start()
    return -1

s = "##catgiraffeapluscompscI"
i = first_letter(s)
print(i)
Comment

get first letter of each word in string python

def abbrevName(name):
    xs = (name)
    name_list = xs.split()
    # print(name_list)

    first = name_list[0][0]
    second = name_list[1][0]

    return(first.upper() + "." + second.upper())
answer = abbrevName("Ozzie Smith")
print(answer) 
Comment

how to find the first letter of an item in python

mylist[0][0]   # get the first character from the first item in the list
Comment

grab the first letter of each string in an array python

def firstLetterOfEachName():
	names = ["Kevin", "Cameron", "Liam", "Meghan"]
	firstLetter = [x[0] for x in names]
    return firstLetter

answer = firstLetterOfEachName()
print(answer)
Comment

PREVIOUS NEXT
Code Example
Python :: multiple input to list 
Python :: python get class from string 
Python :: python treemap example 
Python :: VALUE ERROR EXCEPTION 
Python :: create requirements file and load it in new envirnment. 
Python :: install python macos catalina 
Python :: continue in python 
Python :: enumerate in django templte 
Python :: python max value in list 
Python :: pyttsx3 
Python :: python filter list with lambda 
Python :: convert excel workbook to dataframe 
Python :: python get index of substring in liast 
Python :: python syntax errors 
Python :: plot matrix as heatmap 
Python :: move files in python 
Python :: read xml file in python 
Python :: blur an image in python 
Python :: SUMOFPROD1 
Python :: python dictionary key in range 
Python :: change value in nested dictionary python 
Python :: how to import nltk 
Python :: groupby get last group 
Python :: python tkinter menu widget 
Python :: python single line comment 
Python :: return position of a unique value in python array 
Python :: remove extra blank spaces 
Python :: re.search() 
Python :: python type checking 
Python :: python api request 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =