<jupyter_start><jupyter_text>**List Comprehension**Comparing normal for loop and using list comprehension<jupyter_code># Exercise - 1
names = ['Johnny', 'Sarah', 'Jack', 'Christopher']

# Normal For Loop
l = []
for person in names:
	l.append(person)
print(l)

# Using List Comprehension
print([person for person in names]) 
# Exercise - 1.1

# Normal For Loop
l = []
for person in names:
	l.append(person + ' invited me to dinner')
print(l)

# Using List Comprehension
print([person + ' invited me to dinner' for person in names]) 
# Exercise - 2
movies_and_ratings = {	"Interstellar" : 7, 
			"Dark Knight" : 8,
			"Joker" : 9,
			"Titanic" : 10
					}
# Normal For Loop
l = []
for movie in movies_and_ratings:
	if movies_and_ratings[movie] > 8:
		l.append(movie)
      
print(l)

# Using List Comprehension
print([movie for movie in movies_and_ratings if movies_and_ratings[movie] > 8])<jupyter_output>['Joker', 'Titanic']
['Joker', 'Titanic']
{'fraction_non_alphanumeric': 0.13015873015873017, 'fraction_numerical': 0.01164021164021164, 'mean_word_length': 4.468208092485549, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '640204', 'license': 'MIT', 'n_tokens_mistral': 378, 'n_tokens_neox': 338, 'n_words': 101, 'path': 'coding-exercises-avairds/week4/part1-additional-lectures-loops/list-comprehension.ipynb', 'repo_name': 'Alex-Snow-School-Lab/Python-Basics', 'size': '945'}