One of the ways to easily create dictionaries is through comprehension. Similar to the list comprehension, it’s possible to create a dict with an inline for loop:
Just like in list or set comprehensions, all the rules of filtering or conditional elements apply for dict comprehension as well.
names = ['Bob', 'Anna', 'Charles']
surnames = ['Brown', 'Kennedy', 'Jackson']
people = {names[i]: surnames[i] for i in range(len(names)) if names[i] != 'Anna'}
print(people)
# {'Bob': 'Brown', 'Charles': 'Jackson'}
Challenge
Given n numbers separated by a space, you are asked to create a dictionary that would map the number to its cube, while eliminating all the numbers whose square ends with 6.
The only line of the input contains space-separated numbers.
The program should print numbers that satisfy the condition with their cube.