How to use 'get first letter of string python' in Python

Every line of 'get first letter of string python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
114@register.filter
115def first_letters(string):
116 return ''.join(s[0].upper() for s in string.split(" "))
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

42def firstUniqChar(self, s):
43 """
44 :type s: str
45 :rtype: int
46 """
47 alphabet = 'abcdefghijklmnopqrstyvwxyz'
48 index = len(s)
49 for c in alphabet:
50 if c in s:
51 l = s.find(c)
52 r = s.rfind(c)
53 else:
54 continue
55 if l == r and l < index:
56 index = l
57 if index == len(s):
58 return -1
59 return index

Related snippets