0
items = ["Apple", "Banana", "Cherry", "Date", "Eggfruit", "Fig"]
for word in items:
      print(word[:3])
#This is for getting the first three characters

items = ["Apple", "Banana", "Cherry", "Date", "Eggfruit", "Fig"]
out = map(lambda x:x.upper(), items)
output =  list(out)
print(output)
#This is to get everything in capitals

The first code is for printing the first three characters of each item in the list and the second part prints all the items in capitals-i am not sure what code i need to print the first three characters of each item in capitals

1 Answers1

0

word[:3] is a string of the first three letters, and you can use its upper method directly.

items = ["Apple", "Banana", "Cherry", "Date", "Eggfruit", "Fig"]
for word in items:
      print(word[:3].upper())

There is almost never a reason to use map, filter or reduce. The first two are just functional equivalents of list comprehensions and the latter is also done by itertools.accumulate. They only exist because some language committers like the functional approach of other languages.

tdelaney
  • 73,364
  • 6
  • 83
  • 116