How to print out the first character of each list in Python?PythonServer Side ProgrammingProgramming Show Assuming that the list is collection of strings, the first character of each string is obtained as follows − >>> L1=['aaa','bbb','ccc'] >>> for string in L1: print (string[0]) a b cIf list is a collection of list objects. First element of each list is obtained as follows − >>> L1=[[1,2,3],[4,5,6],[7,8,9]] >>> for list in L1: print (list[0]) 1 4 7Jayashree Published on 15-Feb-2018 08:16:18 Previous Page Print Page Next Page Advertisements String containing first letter of every word in a given string with spaces
String str is given which contains lowercase English letters and spaces. It may contain multiple spaces. Get the first letter of every word and return the result as a string. The result should not contain any space. Examples: Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hcSource: https://www.geeksforgeeks.org/amazon-interview-set-8-2/amp/
Example How tocapitalize the first letter of every word in the listPython simple code. list1 = ["Hello", "how", "are", "you"] for i in range(len(list1)): list1[i] = list1[i].capitalize() print(list1)Output: Another exampleYou can also use the python string title method with the same process. Output: [‘Hello’, ‘How’, ‘Are’, ‘You’] Do comment if you have any doubts and suggestions on this python list topic.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical. Share this:
Related |