<jupyter_start><jupyter_text>Iterators in Python ---------------------<jupyter_code># range
for item in range(1,6,2):
    print(item)
# list
numbers_list = [ 1,2,3,4,5]
numbers_list.append(6)
for item in numbers_list:
    print(item)
# tuples
number_tuple = (1,2,3,4,5)
for item in number_tuple:
    print(item)
# dictionary
qt = { 
    'python': 'khaja',
    'testing': ['Ramana', 'Lakshmi']
}

print("direct iteration")
print()
for item in qt:
    print(item)
print()
print("iterating keys")
print()
for item in qt.keys():
    print(item)
print()
print("iterating values")
print()
for item in qt.values():
    print(item)
print()
print("iterate name and value")
print()
for name, value in qt.items():
    print(f"{name} ==> {value}")

# Sets
even_numbers = { 2,4,6}
for item in even_numbers:
    print(item)
odd_numbers = {1,3,5}
for item in odd_numbers:
    print(item)

print(even_numbers.union(odd_numbers))
print(even_numbers.intersection(odd_numbers))

selected_colors = { 'white', 'green', 'blue'}

generally_liked_colors = {'white', 'blue', 'yellow'}

print(selected_colors.union(generally_liked_colors))

print(selected_colors.intersection(generally_liked_colors))
shopping_cart = {}
shopping_cart['iphone 13'] = {
    'price': 135000,
    'quantity': 5,
    'coupon code': 'BEST5'
}
shopping_cart['one plus 9T'] = {
    'price': '79000',
    'quantity': 5,
    'coupon code': 'BEST10'
}
for name, value in shopping_cart.items():
    print(f"item => {name}")
    print(f"individual price = {value['price']}")
    print(f"quanity => {value['quantity']}")
    print(f"coupon code => {value['coupon code']}")<jupyter_output>item => iphone 13
individual price = 135000
quanity => 5
item => one plus 9T
individual price = 79000
quanity => 5
{'fraction_non_alphanumeric': 0.17478510028653296, 'fraction_numerical': 0.03151862464183381, 'mean_word_length': 4.650485436893204, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, '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': '271544', 'license': 'Apache-2.0', 'n_tokens_mistral': 692, 'n_tokens_neox': 642, 'n_words': 152, 'path': 'Mar22/PythonFundamentals/iterators.ipynb', 'repo_name': 'khajadatascienceR/DataScienceWithPython', 'size': '1745'}