Archive for the ‘Uncategorized’ Category

How to copy or clone list in Python

Lists are ordered collection object type. Lists can contain any sort of object: numbers, strings, tuple,dictionary and even other lists. Lists are mutable objects. How to copy or clone list in Python 1. Create List >>> L=[‘Python’,’R’,’SAS’,’SPSS’,’Java’,’Data Analytics’,[1,2,3,4],10,3.14]

pip installation problem Cannot fetch index base URL

When tried to install nltk using pip, received following error: C:\Users>pip install nltk Downloading/unpacking nltk Cannot fetch index base URL Could not find any downloads that satisfy the requirement nltk Cleaning up… No distributions at all found for nltk Storing debug log for failure in C:\Users\pinnapav\pip\pip.log Solution:Run the command: py -m pip install nltk

How to check list is empty or not in Python

If list contains zero elements or length of list is zero is known as empty list. We can check whether list is empty or not using below methods 1. Declare empty list a=[] #Empty list type(a) 2. Check list is empty or not by using len function of list.

append vs extend in Python

append and extent both are list methods in Python. Following are the definitions of append and extend methods. append extend append is basically used in Python to add one element extend is used to merge two lists or insert multiple elements in one list

How to install pip

What is pip? Pip is recommended tool to install and manage Python packages. Pip installation: 1. Go to site.

Add new keys to dictionary in Python

We can add an item to existing dictionary in Python using following methods. Method1: Using update method of dictionary: 1. Create dictionary: >>> countries={‘United States of America’:’Washington’,’Canada’:’Ottawa’,’India’:’New Delhi’} >>> countries {‘United States of America’: ‘Washington’, ‘Canada’: ‘Ottawa’, ‘India’: ‘New Delhi’}

Difference between Lists and Tuples in Python

List Tuple List objects are mutable objects. Which means can be changed after its created Tuple objects are immutable objects. Which means can’t be changed after its created Lists have order Tuple has structure Iterating the list is slower Iterating the tuple is faster List objects are not used as keys for the dictionary Tuple […]

NameError: name ‘raw_input’ is not defined

Traceback (most recent call last): File “<pyshell#0>”, line 1, in first_name=raw_input() NameError: name ‘raw_input’ is not defined   Reason:

Fibonacci Sequence in Python

What is Fibonacci Sequence? Depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two. Fibonacci Sequence: 0,1,1,2,3,5,8,13,21,34,55,89,144,233, … 1,1,2,3,5,8,13,21,34,55,89,144,233, … Fibonacci Sequence Formula:

Powered by k2schools