Ehsan Ghanbari

Experience, DotNet, Solutions

List Comprehensions in python

I'm a Dot Net developer, but sometimes I jump on other programming languages and I think it helps me to comprehend my main field of activity easily. I was just working with the list in Python. Let's create a simple list:


mylist = ["angular", "javascript", "typeScript"]


print(mylist)  ##For printing the list


for x in mylist  ##For creating a loop through the list



print(len(mylist )) ##For getting the length of the list


mylist.append("backbon")  ##For adding an Item


mylist.Remove("javascript")  ##For removing an item


mylist.clear() ##For clearing the list


Del mylist  ##For deleting the whole list


mylist[1]   ##For getting the member of an index


mylist.Insert(4,"meteor")   ##For inserting an item to a specific index


mylist.Pop()   ##To removing the last member of the list


mylist.reverse()  ## for reversing the list


Python also supports negative indexes. For example, the index of -1 refers to the last item, -2 refers to the second last item etc.


print(Mylist[-2]) ## output:javascript


And it worth mentioning that, python supports for slice as well


print(mylist[1:3])   ## elements 1rd to 3th


print(mylist[:-3])  ## elements beginning to 2th


print(my_list[2:]) ## elements 3th to end

I'm gonna get start coding with python

Just like most of the thirsty developers! I want to have some experience coding on different programming languages. I've decided to get started learning python. At the moment I don't know anything about the syntax and even usages of it. You can read the result of my R&D in the rest of this blog post.

Python is a remarkably powerful dynamic programming language and free to use, even for commercial products and runs on Windows, Linux/Unix and Mac OS. Python has some interesting feature listed in its official website:

  1. very clear, readable syntax
  2. strong introspection capabilities
  3. intuitive object orientation
  4. the natural expression of procedural code
  5. full modularity, supporting hierarchical packages
  6. exception-based error handling
  7. very high-level dynamic data types
  8. extensive standard libraries and third party modules for virtually every task
  9. extensions and modules easily are written in C, C++ (or Java for Jython, or .NET languages for IronPython)
  10. embeddable within applications as a scripting interface


Based on these features, it seems to be a powerful language. it also supports meta-classes and duck typing(I'm not familiar with duck typing!). The most interesting feature of python is its compatibility with .Net and COM objects and supporting multiple programming paradigms, including object-oriented, imperative and functional programming, procedural styles and Internet Communications Engine (ICE). At the time of writing the blog post, the last release of python is python 3.3.3 and available at this address. based on this website's quote, python is the most popular programming language in the world(I didn't think so!).




"Hello world" program via python!

Python has such a cool syntax, it allows programmers to express concepts in fewer lines of code. There is a function in python 3 or later named print, you can write your first python hello world program (I don't want to write anything rather than hello world!)


print("Hello, World!") 


About the IDE of python, I personally prefer to use pycharm as I like JetBrains products, but you can use visual studio 2013 and it's tools for python. I will practice and write more about python ;)


About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns and I'm spending a lot of my time on architecture subject. Since 2008, I've been as a developer for companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the&nb Read More

Post Tags
Pending Blog Posts
Strategic design
Factory Pattern
time out pattern in ajax
Selectors in Jquery
Peridic pattern
How to query over Icollection<> of a type with linq
How to use PagedList In MVC
Domain driven design VS model driven architecture
What's the DDD-lite?
Using Generic type for type casting in F#