September 24

Lists

List is a sequential data type. List values are comma separated and enclose with square bracket.
List in Python is like array in Perl and an array(ArrayList Class) in Java.

Key features of List:

  • List items can be any datatype, within a single list you can have multiple datatype as item
  • List can have duplicate values
  • List is Mutable object
  • Negative index access value from end of the list i.e. tmp_list[n-1] = tmp_list[-1]
  • You can use any integer expression for index

Adding items to list, you can insert item to any place in the list using insert method. append method will insert item at the end.

List has extend and append method,both add values to list but both work differently.
Extend takes single argument,which is always list whereas append can n number of argument and add each item to original list.

Category: Data Types, Lists | Comments Off on Lists
September 24

Dictionary

Dictionary is a key value pair,mapping between a set of keys and a set of values.
Association of a key and a value is called key-value pair or an item.
Python dictionary is like hash in Perl, an instance of Hashtable class in Java or an instance of the Scripting.Dictionary object in Visual Basic.

Key features of dictionaries

  • dictionary can not have duplicate keys
  • assigning new value to existing key will simply replace the old value
  • dictionary value can be any datatype, within a single dictionary you can have multiple datatype as value
  • dictionary key can be any immutable datatype
  • Deleting Items From Dictionaries
    Dictionary has two method to delete/clear the data

    • del, will delete individual item from dictionary
    • clear , will clear all the data and give you a empty dictionary

Category: Data Types, Dictionary | Comments Off on Dictionary