Misc practice questions in Python - Level 1

WAP stands for Write A Program

  1. Write a Python program to create a dictionary using the given lists.
    names = ["MANISH", "SAMARTH", "AYUSH", "ANANYA"]
    ages = [24, 21, 23, 20]

    Use the provided lists to create a dictionary where the names act as keys and ages as values.
    Expected output:
    {'MANISH': 24, 'SAMARTH': 21, 'AYUSH': 23, 'ANANYA': 20}
    _________________
  2. Write a Python program to create a dictionary from a given list of names, where each name is mapped to a string containing only its vowels.
    names = ["MANISH", "SAMARTH", "AYUSH", "ANANYA"]
    Expected Output:
    {'MANISH': 'AI', 'SAMARTH': 'AA', 'AYUSH': 'AU', 'ANANYA': 'AAA'}
    _________________
  3. Write a Python program to create a new list from an existing list, where each element consists of a string and a specified length. The output list should contain substrings truncated to the given length.
    data = [['MANISH', 2], ['SAMARTH', 3], ['AYUSH', 4]]
    Expected Output:
    ol = ['MA', 'SAM', 'AYUS']
    _________________
  4. Write a Python program to generate a nested list from a given list of names. Each element in the output list should be a dictionary, where the key is the name and the value is its length.
    names = ["MANISH", "SAMARTH", "AYUSH", "ANANYA"]
    Expected Output:
    [['MANISH', 6], ['SAMARTH', 7], ['AYUSH', 5], ['ANANYA', 6]]
    _________________
  5. Write a Python program to extract and print only the names from a given list of full names with titles. The titles (Mr. or Ms.) should be removed from the output.
    lnames = ['Mr.Manish', 'Ms.Ananya', 'Ms.Jyotika', 'Mr.Cache']
    Expected Output:
    ['Manish', 'Ananya', 'Jyotika', 'Cache']
    _________________
  6. Write a Python program to determine and print the gender of each person in a given list based on their title (Mr. or Ms.).
    lnames = ['Mr.Manish', 'Ms.Ananya', 'Ms.Jyotika', 'Mr.Coehen']
    Expected Output:
    {'Manish': 'Male', 'Ananya': 'Female', 'Jyotika': 'Female', 'Coehen': 'Male'}
    _________________
  7. Write a Python program to extract and display the age and weight of all individuals from a given dictionary.
    d = {
    1: ['Nitin', 35, 61, 'Gurgaon'],
    2: ['Manish', 34, 55, 'Delhi'],
    3: ['Abhishek', 36, 50, 'Noida']
    }

    Expected Output:
    Nitin –> [35, 61]
    Manish –> [34, 55]
    Abhishek –> [36, 50]
    _________________
  8. Write a Python program to generate passwords dynamically using the name and gender of individuals from a given list.
    Password Format:
    Take the first three letters of the name.
    Append the corresponding gender (Male for “Mr.”, Female for “Ms.”).
    Append the position number (starting from 1).
    lnames = ['Mr.Manish', 'Ms.Ananya', 'Ms.Jyotika', 'Mr.Coehen']
    Expected Output: 
    ManMale1
    AnaFemale2
    JyoFemale3
    CoeMale4
    _________________
  9. Write a Python program to generate a nested list containing details about individuals using the given passList and nameList.
    Each sublist should contain the person’s full name, gender, and assigned number extracted from passList.
    passList = ['ManMale1', 'AnaFemale2', 'JyoFemale3', 'CoeMale4', 'ManMale5']
    nameList = ['Manish', 'Ananya', 'Jyotika', 'Coehen', 'Maninder']

    Expected Output:
    ol = [['Manish', 'Male', 1],
    ['Ananya', 'Female', 2],
    ['Jyotika', 'Female', 3],
    ['Coehen', 'Male', 4],
    ['Maninder', 'Male', 5]]

    _________________
  10. Write a Python program to generate a new list where each name in `nameList` is transformed based on the following rule:  
    – Repeat the first N characters of the name N times, where N is the position of the name.
    nameList = ['Manish', 'Ananya', 'Jyotika', 'Coehen', 'Maninder']
    Expected Output:
    ol = ['M', 'AnAn', 'JyoJyoJyo', 'CoehCoehCoehCoeh', 'ManinManinManinManinManin']