Page 309 - CITS - CSA - TP (Volume 2) - Hindi
P. 309
कं ूटर सॉ वेयर ए ीके शन - CITS
इसिलए, पूरा कोड एक ंग लेता है, गैर-वण माला अ रों को िफ़ र करता है, शेष अ रों को अपरके स म बदलता है, और उन अपरके स अ रों
का एक सेट बनाता है। आउटपुट मूल टे और अपरके स अ रों के प रणामी सेट को दिश त करता है।
आउटपुट :
5 श कोश कॉ ह शन:
श कोश कॉ ह शन आपको श कोश बनाने की अनुमित देती है। वे कुं जी-मान पेयर अिभ यों का उपयोग करते ह ।
टा 7: फलों की मूल सूची और उनकी लंबाई
# Original list of fruits and their lengths
fruits = [‘apple’, ‘banana’, ‘orange’, ‘kiwi’, ‘grape’]
fruit_lengths = {fruit: len(fruit) for fruit in fruits}
# Print the original list
print(“Original List of Fruits:”, fruits)
# Print the dictionary created using a comprehension
print(“Dictionary of Fruit Lengths:”, fruit_lengths)
ीकरण:
1 fruits = [‘apple’, ‘banana’, ‘orange’, ‘kiwi’, ‘grape’]: फलों की सूची आरंभ करता है।
2 fruit_lengths = {fruit: len(fruit) for fruit in fruits}:
• यह एक श कोश समझ है।
• फलों म फलों के िलए: सूची म ेक फल पर पुनरावृि करता है।
• {fruit: len(fruit)}: श कोश म कुं जी-मान यु बनाता है, जहां कुं जी फल है, और मान फल की लंबाई है।
3 print(“Original List of Fruits:”, fruits): फलों की मूल सूची ि ंट करता है।
4 print(“Dictionary of Fruit Lengths:”, fruit_lengths): Prints the dictionary created using the comprehension.
आउटपुट :
टा 8: तापमान से यस म
# Original list of temperatures in Celsius
temperatures_celsius = {‘city1’: 25, ‘city2’: 30, ‘city3’: 22, ‘city4’: 18}
# Dictionary comprehension to convert temperatures to Fahrenheit
temperatures_fahrenheit = {city: (temp * 9/5) + 32 for city, temp in temperatures_celsius.items()}
# Print the original temperatures
print(“Original Temperatures (Celsius):”, temperatures_celsius)
295
CITS : IT & ITES - कं ूटर सॉ वेयर ए ीके शन - अ ास 135

