Python data structure quiz

Data structure (DSA) in Python is well supported by a lot of powerfull class like List,Stack,Queue,Set or Dictionary

This quiz is in Python quiz collection.

Start quiz
  • 1.

    a = ?

    a = [[1] * 2] * 2
    a[0][0]=2

     

  • 2.

    What is the result of this code?

    a=[1,2,3,4,5,6,7,8,9]
    a[::2]

     

  • 3.

    What will be placed in a?

    a = [1,2,3]
    a[-3:-1] = 10,20,30,40

     

  • 4.

    What gets printed?

    kvps = { '1' : 1, '2' : 2 , '3' : 3, '4' : 4, '5' : 5}
    newData = { '1' : 10, '3' : 30 }
    kvps.update(newData)
    x = sum(kvps.values())
    print x
  • 5.

    What gets printed?

    names1 = ['Amir', 'Barry', 'Chales', 'Dao']
    names2 = [name.lower() for name in names1]
    print names2[2][0]
  • 6.

    What gets printed?

    names = ['Amir', 'Barry', 'Chales', 'Dao']
    print names[-1][-1]
  • 7.

    The following code will successfully print the days and then the months

    daysOfWeek = ['Monday',
                  'Tuesday',
                  'Wednesday',
                  'Thursday',
                  'Friday',
                  'Saturday',
                  'Sunday']
    months =             ['Jan', \
                          'Feb', \
                          'Mar', \
                          'Apr', \
                          'May', \
                          'Jun', \
                          'Jul', \
                          'Aug', \
                          'Sep', \
                          'Oct', \
                          'Nov', \
                          'Dec']
    print "DAYS: %s, MONTHS %s" % 
        (daysOfWeek, months)
  • 8.

    What is the ouput?

    dict = {'Name': 'Jill', 'Age': 17, 'Name': 'Bill'}
    print "dict['Name']: ", dict['Name']
  • 9.

    Which of following are valid dictionary declarations?

     

  • 10.

    __________ creates a list.

  • 11.

    What is list("abcd")?

  • 12.

    Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3]

    What is len(list1)? 

  • 13.

    Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3]

    What is max(list1)? 

© 2017 QuizBucket.org