friends = ["Mohamed", "Shady", "ahmed", "eman", "Sherif"]
i = 0
while i < len(friends):
print(friends[i])
i = 1
else:
print("Done")
how to use if condition to print only capitalized names from this list?
CodePudding user response:
for name in [x for x in friends if x[0].isupper()]:
print(name)
other = [x for x in friends if not x[0].isupper()]
CodePudding user response:
lower_names = []
for name in friends:
if name[0].isUpper():
print(name)
else:
lower_names.append(name)
This should check if the first letter is capitalized, and print it if so. Otherwise, it goes into the other list.