Skip to content

Instantly share code, notes, and snippets.

@Manikant92
Created July 20, 2018 10:11
Show Gist options
  • Save Manikant92/4444717f81a10ff2f1502c949328662a to your computer and use it in GitHub Desktop.
Save Manikant92/4444717f81a10ff2f1502c949328662a to your computer and use it in GitHub Desktop.
#multiply elements in x with 11 using list comprehensions in python
y = [i*11 for i in x]
#above is similiar to below
y = []
for i in x:
multiplication = i*11
y.append(multiplication)
#instead of 4 lines of code, we can do same operation in one line using list comprehensions in python as shown above
#output: [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment