Skip to main content

Posts

Python Hunter, Slicing, traversing, copy and pit falling of list and tuple in python. By Pran Sukh

Slicing is a technique in python to pick up data from list,tuple and set from desired location. lets make python a bit more beautiful with slicing technique.  Caution :- No animal is hurt during the development of this tutorial :)   it can be done with three arguments.  e.g dataString [ begin : end : step ] argument begin and end are giving lucid  view, these arguments are to instruct the script that from where the slicing will begin and where it will end, but the tricky argument is the last one ( " step ") . it indicates that how many  index or indices  the code have to   hops or skip to pick up the next slice. In the below example the slicing is starting form 6th index or indices and go till 21th  index and after every slice it will skip the 3 index or indices between the begin and end index.  let's take an example :- 1 25 str = "1abcdefghijklmnopqrstuvwxyz" print ( str [ 6 : 21 : 3 ]) list_1 = [ "T...

Python Hunter, Post on Python Tuple.

Tuple is like list but unlike in structure and functionality. first basic difference is can be figured out by the structure. List elements are enclosed with '[]' brackets but tuple elements are enclosed with '()' parentheses. Few properties of tuple:- 1. It is faster than list. 2. Unlike list, tuple is immutable, i.e. tuple's data cannot be changed once created, we should use tuple if we want our data to be safe from accidental change.  As you can see in title picture, you are allowed to see but cannot touch it. 3. We can use tuple as key in dictionaries   whereas this is not the case with list,  we can’t use list as key in dictionary <Link this post (dictionary) will be available on 16 March 2018>.      Examples:-  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 myTuple= tuple ( 'Python' ) # it takes only one parameter print (myTuple) #it will break down each character into separate elements, just l...

List, Tuple and manipulation operation on Python Hunter's blog.

   List   in python are the most flexible datatype in python. Python list looks identical to c++ and java's array (elements separated by ',' coma) but unlike in features. Like c++ and java's array hold only similar types of elements (e.g String, int, double) and these programming languages have limitation to grow the size of their declared array at run time, array size has to defined at compile time (there could be some logic to decide the array size at run by getting the user's input but, after that it will be fixed, but it is not recommended) But Python list is slightly different from c++ and Java's array as it can grow it's size at run time and hold any multiple dataType in one single list (e.g string, int, char, Boolean....... all together in one list ).      # Following are the ways to create list. Output:- ---------------------- Source Code Starts -------------------- 1 2 3 4 5 6 7 8 9 10 1...