Friday, January 29, 2016

A Smooth Refresher on Python's Lists

Python is a wonderful language. Well, it at least taught Gloria to love again! This is an expected thing to happen with a language packed with many attractive features. It is free and open source, simple, easy to learn, etc. It is thus no surprise that Python came in 5th place among 20 other programming languages in 2015, having a lead over well-known languages like PHP and JavaScript. Check out the source for this statistic.

I'm pretty sure that the reasons mentioned above could be sufficient for someone to move to Python as the language of choice. And, here comes my role. I will try to make such a transition as smooth as possible, by teaching you important concepts in Python in a simple manner.

Enough introduction, and let's get started! In this article, I will review (or introduce) an important concept in Python, Lists, which is necessary to know before moving forward towards more advanced topics. 

Suppose you have created a list of tasks to work on for the day. In other words, you have created a to-do list. Say that your to-do list was as follows:

  • write blog post
  • reply to email
  • read in a book

Let's write this list in Python. One way to do that is assign each to-do task to a variable, as follows:

todo1 = 'write blog post'

todo2 = 'reply to email'

todo3 = 'read in a book'

What if we had a longer list of to-dos? It is not feasible to assign each to-do a separate variable, is it? Lists here come into play. 

Python lists are considered the most versatile data type. Lists are created using square brackets [ ]. The values (items) of the list are inserted between those square brackets, and separated by a comma. So, let's see what our above to-do list would look like using lists.

todo = ['write blog post', 'reply to email', 'read in a book']

Great! But that's not all—there is more we can do with lists, as will be shown in a moment.

Accessing Items

Lists make it easy to access items regardless of the number of items you have in the list. This is done using an index. For instance, our todo list consists of three items. In Python, indexing starts from the value 0. So, the first item in the list will have index 0, the second item index 1, and so forth.

Let's say we want to access the last item in the todo list, that is 'read in a book'. This can be simply done as follows:

todo[2]

List Operations

At the end of the day, you should have finished the tasks or at least some task on your to-do list. Say that you have written a blog post. In this case, you need to remove this to-do from the list. In order to do that, you can simply use the function del. The task we want to remove is the task with index 0. So, in order to remove that item from the list, type the following:

del todo[0]

In this case, our todo list will look as follows:

todo = ['reply to email', 'read in a book']

Oh, you now realized that you would like to replace the read in a book task with read 5-pages from the book in order to be more specific, especially when you realized that this is a good practice for getting things done (GTD). All you need to do is access the index of that element, and type your new task:

todo[1] = 'read 5-pages from the book'

The todo list will now look as follows:

['reply to email', 'read 5-pages from the book']

Well, you feel you have some time for a new task, and you decided to add the task call the consultation service at the end of your todo list. This can be simply done using the append() function, as follows:

todo.append('call the consultation service')

The todo list will now look as follows:

['reply to email', 'read 5-pages from the book','call the consultation service']

Wait a minute, you remember that you had an old to-do list old_todo that you decided to combine with your current to-do list todo. Is there a way to do that, or do we have to copy and paste the items from the old list to the current one?

old_todo = ['buy grocery', 'wash car', 'borrow a book from the library']

You can simply concatenate the two lists using the + operator as follows:

new_todo = todo + old_todo

The new to-do list new_todo will now look as follows:

['reply to email', 'read 5 pages from the book', 'call the consultation service', 'buy grocery', 'wash car', 'borrow a book from the library']

Notice if you wrote new_todo = old_todo + todo, items in old_todo will come first in the new list.

We now have a nice to-do list. Let's see how many items we have so far. Simply type:

len(new_todo)

You should get six items. A reasonable number of tasks for your day, I guess.

Say that you have a very long list, and you just wanted to make sure that you have a particular task listed. Rather than manually looking for that item, you can use in as follows:

'wash car' in new_todo

If the item 'wash car' is in the list, you should get True as a return value.

List of Lists

Lists, as we have seen, are very flexible object types. The nice thing about lists is that they can contain any object type, even lists!

For instance, you can create a list that looks as follows:

complex_list =['Abder', '4.0', ['write blog post','grocery'],[['a','b','d','e','r'],['number','todo']]]

Notice that the list not only contains different object types and a list, but also a list of lists. Isn't that wonderful?

The for-loop and Lists

Lists can be used with the for-loop in an interesting way. I will show one example of this in this section. 

Say that you have the following list and you wanted to repeat each item three times:

abder = ['a','b','d','e','r']

You can do this as follows:

new_list = []

abder=['a','b','d','e','r']

for r in abder:

    new_list.append(r * 3)

The result will thus be:

['aaa', 'bbb', 'ddd', 'eee', 'rrr']

Takeaways

From this article, we can see the power, flexibility, and simplicity of Python represented in its Lists. Lists proved itself as a very versatile object type through which we can group different object types, including other Lists, and perform different operations on the List in a simple manner. For more operations on Lists, you can consult Python's documentation.

What's the thing you liked most about Lists?


by Abder-Rahman Ali via Envato Tuts+ Code

This week's JavaScript news, issue 268

This week's JavaScript news
Read this e-mail on the Web
JavaScript Weekly
Issue 268 — January 29, 2016
Flexible and with a great demo page. Supports numerous controls, modal and inline use, flipping, rotation, and more.
Fengyuan Chen

An attempt to recreate React’s core functionality with as little code as possible and with first-class ES6 support. There are lots of demos to check out.
Jason Miller

Coming to a Chrome (49) and Node near you. It has 91% ES6 support (by the Kangax compatibility table) including Proxy objects and the Reflect API.
V8 Project

Learn React and level up your JavaScript skill set. Join 3,494 other developers learning React with Wes Bos in this tutorial series. React for Beginners will have you learn React.js in just a couple of afternoons, and it’s currently reduced to its launch price too. Check it out.
Wes Bos   Sponsored
Wes Bos

“I think that there is an opportunity to do the same with React, but I am concerned that we could also go in another direction..” Key thoughts and insights from an industry expert.
Dion Almaer

One library’s solution to approaching client-side modularity using a mono-repo, one npm package and several CommonJS require-able modules.
plotly

Cody Lindley says component architectures are a cornerstone of all modern front end libraries/frameworks and shows how they work in some of them.
Telerik Developer Network

An attempt to unpack the complicated world of modules and module-like systems used in JavaScript.
Preethi Kasireddy

1.8 supports consumption of normal JavaScript files alongside TypeScript ones, making migrations easier. Extra JSX support is also included.
Microsoft

Google’s Jake Archibald is excited about the potential of streams in browsers to improve Web responsiveness. A look at the future?
Jake Archibald

Jobs

  • JavaScript Developers at X-Team (Remote)We're looking for developers with extensive knowledge of JavaScript. The perfect candidate would be highly skilled in different frameworks and libraries. We are 100% remote and we provide the funding needed to help you achieve your goals and grow as a remote developer. X-Team
  • Senior Node Engineer at TES USA (San Francisco, CA or remote)Make a difference in teachers’ lives with a platform that allows them to find, share and sell resources worldwide. Join TES USA’s small, global team to embrace challenges, be part of a lean process, and impact education. TES USA
  • Stop Applying to Jobs - Let Companies Apply to YouOn Hired, sign up in 10 minutes and get offers from top companies like Facebook, Uber, & Stripe. Engineers get an average of 5 offers on the platform in 1 week. Try it today. Hired.com

In brief

Curated by Peter Cooper and published by Cooper Press.

Stop getting JavaScript Weekly : Change email address : Read this issue on the Web

© Cooper Press Ltd. Office 30, Lincoln Way, Louth, LN11 0LS, UK


by via JavaScript Weekly

How to Install a WordPress Plugin

Want to Learn Something New, in Just 60 Seconds?

Building Business Ideas That Succeed: How to Preflight Your Ideas

ms-podcast182-pat-flynn-560

Do you have a great idea for a business? Is there a new product you want to create? To discover how to improve your chances for success, I interview Pat Flynn. More About This Show The Social Media Marketing podcast is an on-demand talk radio show from Social Media Examiner. It’s designed to help busy marketers [...]

This post Building Business Ideas That Succeed: How to Preflight Your Ideas first appeared on .
- Your Guide to the Social Media Jungle


by Michael Stelzner via

The Grey Tales

Four stories about elephants from around the world. Discover the secret life of elephants and why we need to protect them.
by via Awwwards - Sites of the day

Thursday, January 28, 2016

Facebook, Google Adwords, YouTube, Twitter, LinkedIn: Ad Dimensions Cheat Sheet - #infographic

Infographic: Ad Dimensions Cheat Sheet

Social media marketing could never be utilized to the fullest without relying on advertising. The stats are proof enough of this What makes social ads so powerful is not only do they take advantage of the popularity of social media platforms, but they also have a way of getting businesses to their target audience based on the latter's social media activity alone.

This is one of the main reasons why online businesses should grab at the opportunity that social advertising provides. Much like other forms of advertising, though, social media like Facebook, YouTube, Twitter, and LinkedIn have their own standards when it comes to placing ads on their sites. Factors such as ad types, ad dimensions, character limits on the title and description, etc. would still have to be considered to make sure that no ad guidelines are broken. This applies for both desktop and mobile versions.

For a complete list of types of ads that each social channel is offering, use the ad dimension infographic (featured below) designed by Dot Com Infoway. It provides a convenient view of the various ad sizes that you can choose from statistics and figures regarding the best performing ads are included as well.

by Irfan Ahmad via Digital Information World