Foundations of Python

You are currently auditing this course.
105 / 134

Python Dictionaries and Tuples

Overview

As part of this session, we will learn the following:

  1. Python Dictionaries
  2. Comparison of Python Lists and Dictionaries
  3. Adding values in Dictionary
  4. Dictionary Tracebacks
  5. Get method for Dictionaries
  6. Counting words in a paragraph
  7. Looping in Dictionaries
  8. Python Tuples
  9. Things not to do with tuples
  10. Tuples and Dictionaries
  11. Sorting tuples
  12. Finding top 10 frequent words in a file
  13. Tuple syntax
  14. Tuple Immutability
  15. Tuples in Assignment Statements
  16. Sorting Dictionaries by Either Key or Value

Recording of Session


Slides

Code Repository for the course on GitHub



No hints are availble for this assesment

Answer is not availble for this assesment

Please login to comment

259 Comments

v=f(i) what does (i) and v mean?

 

  Upvote    Share

n the expression v = f(i), (i) represents the input argument or parameter that is passed to the function f().

The v represents the output or result of the function f(). After the function is called with the input argument (i), it performs some computation or processing and returns a value, which is assigned to the variable v. The specific meaning of v will depend on the function and its intended purpose.

  Upvote    Share

This comment has been removed.

This comment has been removed.

This comment has been removed.

def m(b):
    g = b.split(" ")

    c = {}
    for i in g:
        if i in c:
            c[i] = c[i] + 1
        else:
            c[i] = 1
    return c


print(m("the quick brown fox jumps over the lazy dog"))
  Upvote    Share

This comment has been removed.

This comment has been removed.

sir, I might not be able to complete this course in the allotted time for the course completion as my end session exams are coming so I would like to know how to complete the course even after the passing of my lab's approval date? and how can I evaluate my answers without a lab console so that I can complete this course and get certified?

 4  Upvote    Share

v=f(i)

 

What it does??

r=[]

Why did you take this??

  Upvote    Share

r = []  -- Defines an empty list.

v = f(i) -- Accessing element at index i in type f

  Upvote    Share

HI team, Will I be getting a certificate post completion of this python course?

 1  Upvote    Share

Hi Anagha

For free python course, there is no certificate provided

Regards

 

  Upvote    Share

I am not able to sign in to lab.lab subcription validity is not expired

  Upvote    Share

Hi,

I have reset your password, please try to login once again and let me know if it is working fine now. Also, this time try to type in the password instead of copy pasting it.

Thanks.

 1  Upvote    Share

Thankyou  Sir. its working now.

  Upvote    Share

how to access the keys of a dictionary with the help of values???

 

  Upvote    Share

Hi, 

You can write something like:

if dict[key]==value:
    print(key)

Thanks.

  Upvote    Share

what if i have to sort huge data and then i have to call large number of keys with help of values??? i mean is there any method or function for this that we can use here????

  Upvote    Share

Hi,

You may create a function for yourself. Iterate through dictionary and check for value and get the key. 

Thanks.

  Upvote    Share

Top 10 most common words

 

Why are we appending in counts.items??

1st.append(key,val)

 

Please tell.

 

  Upvote    Share

Hi,

Please share the screenshot of where exactly you are facing the issue.

Thanks.

  Upvote    Share

I did not understand.

 

r=[]

 

Why we are taking this??

 

How we are appending it and how it appends??

 

tell answer

  Upvote    Share

This comment has been removed.

Hi Nirav,

In Python, this is one way to initialize a list it is similar to 'list()'. So both 

r = [] 

and 

r = list()

are same.

So I think if this is a list object then `append` function will work to add a element in the list.

Hope this helps you. Happy learning :)

 1  Upvote    Share

How do you comment multiple lines of code prefixing with with hash  - do we have any option on Jupiter tooll bar?

  Upvote    Share

Hi Chitra,

You have to select the lines which you want to comment on, and then hit the `ctrl` and `/` on windows or Linux. if you are working on the Mac then you have to hit the `cmd` + `/`.

You can use the same keys to uncomment as well if you select the commented lines.

Hope this help.

Happy learning :)

P.S. I am sure you already look the jupyter notebook keyboard shortcuts(Help -> Keyboard shortcuts) which is actually fasten the development 

 1  Upvote    Share

whenever I am creating a file and try to open it or run it from jupyter notebook, it says file not found

 

  Upvote    Share

Hi,

Could you please give me more details about how you are creating a file, and how are you trying to run it?

Thanks.

  Upvote    Share

Can a dictionary have multiple keys with a single value ?

  Upvote    Share

Hi,

Dictionary keys should be unique.

Thanks.

  Upvote    Share

Can I access a key form dictionary using vlaue ?

  Upvote    Share

Hi Chaitra,

Interesting question. Dictionary is like hashmap so it gives you the value at a key in O(1) time.

For your question, why do not you give it a shot yourself? :) Few ideas to solve this can be - Reverse the dictionary or use a dictionary comprehension to create a lookup dictionary and then use that to find the key from the value 

  Upvote    Share

This comment has been removed.

Sir

For any doubt is there any possibility to contact you over the phone.

Regards

Rajesh

  Upvote    Share

Hi,

For any doubts/queries, you can leave a comment below the respective tutorial and we will revert to you.

Thanks.

  Upvote    Share

This comment has been removed.

hi how  i can access your code from github

  Upvote    Share

Hi,

You can find our GitHub repository at the below link:

https://github.com/cloudxlab/ml

Also, you can clone our repository using the below command on a web console:

git clone https://github.com/cloudxlab/ml ~/ml

Thanks.

  Upvote    Share

is " line" a special command when we open a text file and we need to go word by word rather than line by line what will we do??

 

  Upvote    Share

Hi,

Could you please tell me which part of the tutorial are you referring to?

Thanks.

  Upvote    Share

when we open a text file to run in python

how to operate along each word

ex

fhandle = open("mbox.txt")

count = 0

for line in fhandle

this "line" is a variable or any command that we use to go line wise in a document

 

  Upvote    Share

Hi,

This line is a variable.

Thanks.

  Upvote    Share

Hi Team,

 

In python How to check whether file location is exists or not. For Example

with open("file lcoation") as f :

before calling a above script want to check file location is valid or not .

  Upvote    Share

Hi,

Good question!

You can try the following:

try:
    my_abs_path = my_file.resolve(strict=True)
except FileNotFoundError:
    # doesn't exist
else:
    # exists

You can go through the below link for more details:

https://stackoverflow.com/questions/82831/how-do-i-check-whether-a-file-exists-without-exceptions

Thanks.

  Upvote    Share

Hi Team,

Please help to read exception class , if any exception occure in try : except bolck, what i mean to ask how to get inner exception or Stack message in Python

  Upvote    Share

hi,

do we have to define mymap function every time as it is not running the code otherwise?

  Upvote    Share

Hi,

These are codes shown as examples, you do not need to replicate them. You will have numerous coding assignments as you move forward in this course. Also, if you want to view the codes shown in the lecture video, you can refer to our GitHub repository for the latest version of these codes from the below link:

https://github.com/cloudxlab/ml/tree/master/python

Thanks.

  Upvote    Share

input:

counts=dict()
names=['jayu','jayateerth','jayateertha','jaya','jayu']
for name in names:
    if name not in counts:
        counts[name]=1
    else:
        counts[name]=counts[name]+1
print(counts)

output:

{'jayu': 2, 'jayateerth': 1, 'jayateertha': 1, 'jaya': 1}

Dint understand the logic of this code. Pl explain

  Upvote    Share

Hi,

We are iterating through the names and checking if a name is already present as a key in the counts dictionary. If no, a new key-value pair with the name as key and value as 1 is created. Else, the count of the name is increased by 1. Hope this helps.

Thanks.

  Upvote    Share

ok thank you

  Upvote    Share

a=list()
a[0]=1
print(a)

output:

list assignment index out of range

I dint get this error for dict but getting error here in assigning for list.Can somebody tell why its showing error

 

 

  Upvote    Share

Hi,

a is an empty list, but you're attempting to write to element [0] in the first iteration, which doesn't exist yet.

Try the following instead, to add a new element to the end of the list:

a.append(1)

Thanks.

  Upvote    Share

but it is possible in empty dict 

a=dict()
a["lenovo"]="sammy"
print(a)

Output:

{'lenovo': 'sammy'}
  Upvote    Share

Hi,

Yes you are right. This is possible with a dictionary but not with empty list. For empty list, we need to use append.

Thanks.

  Upvote    Share

ok thank you

  Upvote    Share

WHY IN OTHER IDE IT SAYS THAT sq IS NOT DEFINED

  Upvote    Share

Hi,

Could you please tell me where does it say "sq is not defined"?

Thanks.

  Upvote    Share

PYChram

 

  Upvote    Share

?

  Upvote    Share

Hi,

Please check with the PyCharm help and FAQ for a solution.

Thanks.

  Upvote    Share

this notebook never reads my any file

i don't why ->

  Upvote    Share

Can you show me the code?

  Upvote    Share

here it is 

  Upvote    Share

Hi,

Please make sure the file exists and the provided path is correct.

Thanks.

  Upvote    Share

Python ain't easy.

  Upvote    Share

hi There 

I am facing 500 : Internal server error

 1  Upvote    Share

Hi,

Are you still facing this issue? If yes, then please share a screenshot.

Thanks.

  Upvote    Share

Hi there,

Facing below error:

 

  Upvote    Share

Hi,

Are you still facing this issue?

Thanks.

  Upvote    Share

Sorted now. Thanks :)

  Upvote    Share

does built in methods like max work on list with different data types

  Upvote    Share

Hi,

Instead of me answering this for you, let me help you finding the answer. Please create a list and then use the max() function on the same.

Thanks.

  Upvote    Share

Hi Sandeep sir , my username and password is still not working in jupiter notebook . Kindly help

 Please see the above screenshot. 

  Upvote    Share

Hi,

Your password has been reset. Please re-try now.

Thanks.

  Upvote    Share

Hello Sandeep sir,my lab username and password is not working and showing invalid . earlier it was working . when I am starting my tuples videos it is not working now .kindly help 

 

  Upvote    Share

Hi Syed,

Sorry for the inconvenience, i have reset your password, please try again.

  Upvote    Share

please explain 

counts[name] = counts.get(name,0) +1

  Upvote    Share

Hi,

get method of a dictionary returns the value associated with the specified key. Here, counts.get(name,0) returns counts[name]; if that key doesn't't exist, then 0 will be returned. Thus, counts[name] = counts.get(name,0) +1 means, if the key is there, its values gets incremented by 1; else, count[name] becomes 0+1 which is 1. Hope this helps.

Thanks.

  Upvote    Share

what is problem in

counts = dict()
names = ['cwen','csev','zqian','cwen']
for name in names :
    if name not in counts :
        count[name] = 1
    else :
        counts[name] = counts[name] +1
print(counts)

  Upvote    Share

Hi,

Would suggest you to have a look at the answer.

Thanks.

  Upvote    Share

Still problem persists

  Upvote    Share

Hi,

Try to stop your server(by clicking on control-panel option on top-right side of the notebook), then click on my server. After it connects, refresh your page. Hope this helps.

Thanks.

  Upvote    Share

Not able to connect Jupyter notebook

request your help

 

  Upvote    Share

please explain word by word 

def mymap (a,f):
    r = [ ]
    for i in a:
        v = f(i)
        r.append(v)
    return r
mymap([1,2,3], sq)

plz exp   r.append(v) this too

  Upvote    Share

Hi,

We are passing the array to calculate the square of each item in the array and append the result.

Thanks.

  Upvote    Share

please explain word by word 

def mymap (a,f):
    r = [ ]
    for i in a:
        v = f(i)
        r.append(v)
    return r
mymap([1,2,3], sq)

  Upvote    Share

Are there any sine/cosine functions in python library?

If yes, could you please explain how can I use them?

  Upvote    Share

Hi,

Have a look at this https://www.geeksforgeeks.org/mathematical-functions-in-python-set-3-trigonometric-and-angular-functions/.

Thanks.

  Upvote    Share

  • what is wrong in this code?
  Upvote    Share

Hi,

Try this:

c = dict()
names = ('name1','name1','name2','name1','name3','name2')
for name in names:
    c[name] = c.get(name,0)+1

Thanks.

  Upvote    Share

At 00:48:10 ;\

both

>>> x = lambda x : x*x

>>>  f =  lambda x : x*x

>>> f(4)

16

are same .

So how for calling a function we're giving it a name as f & x both are same, what's the difference.......??? to give the name to the function we can do f (x) = lambda x: x*x, isn't it??? then pass the argument.

 

 

  Upvote    Share

Hi Kranti,

The x was a typo, so Sandeep just changed the name to f.

Thanks.

  Upvote    Share

Hi, I would like to request timestamps for these lectures on Youtube. I think it will be really helpful for referring back to the lecture for doubts and also in general for traversing the lecture.

 1  Upvote    Share

Hi,

Thanks for your feedback. We have similar plans to make these videos more accessible. We would definitely consider this during our future updates.

Thanks.

  Upvote    Share

 

@ 02:09:17 pls play the video for 1-2 min til 02:12:15  to understand the context... didn't understand after Sandeep finishes the explanation.

 

  Upvote    Share

Hi Kranti,

It is returning False because y is of string type whereas there's nothing assigned to x and hence x and y are not equal.

Thanks and Regards,

Shubh Wadekar

 1  Upvote    Share

This comment has been removed.

why is this happening many times that when I'm posting screenshot together with question, the screenshot doesn't show up... then I've to post it again 

 

@ 02:07:35 why I'm getting False or erroneous result,, results are incorrect, code is running okay.

Means why I'm getting "True" in result if I've defined it "False"

please suggest what's wrong. here the timing is referring the code which Sandeep is explaining, so I tried a similar type of code just to check different type of entry and what kinda results I'll get so here I'm talking about code and my result similar to Sandeep's explanation, it's not exactly same as he is telling.

 

  Upvote    Share

Hi Kranti,

'housekeys' in mybag
The above command is just checking if it exists in the dictinary and as it exists in the dictionary, it's returning True.

Thanks and Regards,

Shubh Wadekar

  Upvote    Share

This means my code won't check whether the tag housekeys is True or False, my code will just return the status of the TAG housekeys whether this tag is present in the bag or not, m I rt?

but then what is the use of this code which can't alert me if i lost my keys from my bog or forgot to keep it in my bag, if I run such code after my packing is done to get the status of my valuables present in the bag, means in physical / actual my bag contains those tags as well as tag's value or status.

 

  Upvote    Share

Hi,

Going by your example in your previous comment, here you are not checking whether the house key is present in your bag because you are not checking the value of the house key. Instead, you are checking the key in the dictionary that whether there is a place for house key present in your bag.

Thanks.

 1  Upvote    Share

Got it,

only checking Tag won't serve my purpose of checking the physical presence of my house key, suppose if Tag is present but physically I forgot to put my keys in the bag then how could I get an alarm regarding missing keys in tag housekeys...

then how to check the value means actually key is present or absent, etc ,, pls call if I'm not clear ,,, I understood ur point, just to check tag but my point is different so suggest me how can I do that 

  Upvote    Share

Hi,

You can traverse the dictionary and check the value of every key.

Thanks.

  Upvote    Share

@ 02:07:35 why I'm getting False or erroneous result,, results are incorrect, code is running okay.

Means why I'm getting "True" in result if I've defined it "False"

please suggest what's wrong. here the timing is referring the code which Sandeep is explaining, so I tried a similar type of code just to check different type of entry and what kinda results I'll get so here I'm talking about code and my result similar to Sandeep's explanation, it's not exactly same as he is telling.

 

  Upvote    Share

Hi Kranti,

Can you share the screenshot of the error with your code?

Thanks and Regards,

Shubh Wadekar

  Upvote    Share

I've written in context with the same question mentioned above, it has scrnsht.... Raj is attending it ,,, 

  Upvote    Share

At 00:48:10 ;\

both

>>> x = lambda x : x*x

>>>  f =  lambda x : x*x

>>> f(4)

16

are same .

So how for calling a function we're giving it a name as f & x both are same, what's the difference.......??? to give the name to the function we can do f (x) = lambda x: x*x, isn't it??? then pass the argument.

  Upvote    Share

Hi,

I could not find the same mentioned at 00:48:10 timestamp of the video. Could you please check and let me know if it is at any other location.

Thanks.

  Upvote    Share

pls play the video for at least 10-20 sec you'll find it..

  Upvote    Share

Hi,

I did, and I was unable to find it. Could you please recheck and share a screenshot maybe.

Thanks.

  Upvote    Share

It has taken around 10 mins to do this because of refreshing stuff pls , enhance it 

 

  Upvote    Share

and why not pic is sending in 1st post 

 

 

  Upvote    Share

 

 

  Upvote    Share

Hi,

I have replied to your query above. Please check.

Thanks.

  Upvote    Share

at 2:33:35,

it is being said that SORT on a LIST is done based on the key, but aren't we sorting it by value? Or what has been implied is that we have interchanged value and key with each other of dictionary items while appending it to another empty list?

Thanks.

  Upvote    Share

Hi,

Here we are saving a key, value tuple in this list and we are sorting based on that key.

Thanks.

  Upvote    Share

What is a dynamic list? How is it different from a list in python?

  Upvote    Share

Hi,

Good question!

A dynamic list in Python is a list which resizes everytime an element is appended to it.

Thanks.

  Upvote    Share

Hi sir, can you please tell me more about 'Tuples are comparable' with examples?

  Upvote    Share

Hi,

Would request you to refer to assessment 122.

Thanks.

  Upvote    Share

This comment has been removed.

REFERENCE TIMESTAMP : 1:59:30

word_count1=dict()
line1=input('Enter the text:')     #user_input
words1=line1.split()
for word1 in words1:
 word_count1[word1]=word_count1.get(word1,0)+1
bigcount is None
bigword is None
for word1,count in word_count1.items():
    if count>bigcount:
        bigword=word1
        bigcount=count
print(bigword,bigcount)

 

OUTPUT:

Enter the text:this is a line of this text
text 7

 

Shouldn't the output be,

this 2

since 'this' is appearing 2 times in the text entered, which is the most no of times?

 

Thanks.

 

  Upvote    Share

Hi,

We do not have any provision for manual assessments. Would suggest you to post this on the discussion forum for peer review.

Thanks.

  Upvote    Share

How do we run FOR loop in reverse in Python? 

  Upvote    Share

Hi,

Good question! Here's an example:

N = 4
print ("The reversed numbers are : ", end = "") 
for num in reversed(range(N + 1)) : 
    print (num, end = " ") 

Thanks.

  Upvote    Share

Okay, for reversing in FOR loop, we have inbuilt 'reversed'.

Can you explain the print statement before the for loop and the one inside. What is   end=" " doing?

Thanks.

  Upvote    Share

Hi,

Python’s print() function comes with a parameter called ‘end’. By default, the value of this parameter is ‘\n’, i.e. the new line character. You can end a print statement with any character/string using this parameter.

Thanks.

  Upvote    Share

Can we call another lambda inside lambda function.

  Upvote    Share

Hi,

Very interesting question! Yes, we can have nested lambda functions. Here is an example:

f = lambda a = 8, b = 7:lambda c: a+b+c 
  
o = f() 
print(o(4)) 

Thanks.

  Upvote    Share

Hi,

at 00:45:25, how is print function returning NONE?

Thanks.

  Upvote    Share

Hi,

This is because print does not return any value but prints it. So it is returning None.

Thanks.

  Upvote    Share

Hi,

Can a module be imported inside a user defined function?

Thanks.

  Upvote    Share

Hi,

It is always best practice to import modules at the starting/top of any program. However, one can also import inside a user-defined function.

Hope this helps. 

Thanks.

 1  Upvote    Share

Hi 

Please help me out in getting the codes from Github, unable to find them.

Thanks

  Upvote    Share

Hi Apratimkumar,

Try Python - Part I or follow this link: https://github.com/cloudxlab/ml/blob/master/python/Python%20-%20Part%20I.ipynb

Thanks

  Upvote    Share

This comment has been removed.

Most of the time cloudx lab is not working it showing message "Not connected "

due to this lot of time get wasted , unable to do practice 

  Upvote    Share

Hi,

Would suggest you to go through our Fair Usage Policy to know about the best practices on using our lab:

https://cloudxlab.com/faq/6/what-are-the-limits-on-the-usage-of-lab-or-what-is-the-fair-usage-policy-fup

Thanks.

  Upvote    Share

Hi sir, 

I have completed 105/134 till now but i got a mail saying Your course progress till now is - 12%.

Sir, why is my progress is not getting saved.

Regards,

Aprajita

 

 

 

  Upvote    Share

Hi,

Your overall course progress is 32%, are you still facing this issue?

Thanks.

  Upvote    Share

Lambda function will work with square and cube command otherwise need to wrote the

  Upvote    Share

Hi,

Are you facing any challenges with this?

Thanks.

  Upvote    Share

For lambda functions expression is necessary to write or command like square and cube will work to run

  Upvote    Share

Hi,

We have a separate topic on lambda functions, would request you to go through the same to get a better understanding.

Thanks.

  Upvote    Share

I am getting error in running simpleexp.py as error showing , pls help how can u get access the github files

  Upvote    Share

Hi,

You need to mention the path for the file simpleexp.py. Also, you can clone out github repository using the following command in a web console:

git clone https://github.com/cloudxlab/ml

Thanks.

  Upvote    Share

I am getting invalid username or password for lab

  Upvote    Share

Hi,

I checked from my end, you account is active and working fine. Would request you to type in your username and password instead of copy pasting them.

Thanks.

  Upvote    Share
  File "<ipython-input-5-966579fc4f6f>", line 5
    print(purse)
    ^
IndentationError: unexpected indent
  Upvote    Share

Hi,

This is the code for which assessment?

Thanks.

  Upvote    Share

Can we use lambda functions as password encryption algorythm?

Ref# Session video 41:23

  Upvote    Share

Hi,

You can, but password encryption algorithms require something more sophisticated than that.

Thanks.

  Upvote    Share

This comment has been removed.

counts = {'one':1,'Two':2,'three':3,'four':4}
for key1 in counts:
    print(counts[key])

why its printing 4??    

  Upvote    Share

Hi,

Could you please tell me which slides, or which part of the video are you referring to?

Thanks.

  Upvote    Share

Hello sir

Can you please tell me what is meant by zero-based or one-based?

Regards 

Prithvi Kaushik

  Upvote    Share

Hi,

Could you please tell me which slides, or which part of the video are you referring to?

Thanks.

  Upvote    Share

Hi sir

I am referring to the question asked at 1:31:55 in the videos.

Thanks

Prithvi Kaushik

  Upvote    Share

Hi,

Here they are referring to 0-based indexing where the index of a data structure, like an array, starts from zero. What this means is that the first element of that data structure starts from zero.

Thanks.

  Upvote    Share

Hello,
I am not getting the file words.txt and clown.txt for running this example given in Dictionary pdf

  Upvote    Share

how to use github properly for this course please help

  Upvote    Share

Hi,

Our GitHub repository hosts all the latest notebooks that were referred in this course. You can clone the GitHub repository to access those notebooks in your lab using the following command (please try this command in the console and not the Jupyter notebook):

git clone https://github.com/cloudxla... ~/ml

If you want to know more about GitHub, you can follow the below link:
https://product.hubspot.com...
Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

hi Team,
i am receiving error while executing code same as in the class, i tried importing square and cubic function,but error throws does not find.please help.

  Upvote    Share

Like the error statement, there is no function or variable called sq in the code

-- Praveen Pavithran

  Upvote    Share

Hi Team,
I have completed Python foundations course and grabbed the knowledge by completing exercises. However both are showing 59% and 85% completed,please help me to shows correctly as possible as it is.

  Upvote    Share

It should be correct now.

  Upvote    Share

There is no " print " here.Then how come the answer got printed ?

  Upvote    Share

Last...line of the code will be displayed.

  Upvote    Share

Closing ticket

-- Praveen Pavithran

  Upvote    Share

Jupyter prints the value for such statement

-- Praveen Pavithran

  Upvote    Share

how to install gotool lib from GIThub

  Upvote    Share

Rakhi,

Could you tell me why you need this tool for this assignment?

-- Praveen Pavithran

  Upvote    Share

Hi Team,
i am trying to run below code but i am getting error. please help and advise me solve the error.
my code:-

chek ([1, 2, 3], lambda x: x*2)

output:-

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-2-0c94f61af1f5> in <module>
----> 1 chek([1, 2, 3], lambda x: x*2)

NameError: name 'chek' is not defined

  Upvote    Share

Hi,

Would request you to share a screenshot of your code and the error that you are getting.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Here is screenshot, pls help

  Upvote    Share

Hi,

There are no chek functions in Python, which is why you are getting this error. You can try and use the map() function instead, it takes a list and a lambda function as an input.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

I am facing an issue using jupyter besides the learning content. How do I open my own .py file in the jupyter in the same window on the side bar. Can someone please help me with this. I mean how do I open my python file in the Jupyter notebook in the playground.

  Upvote    Share

Hi,

The Jupyter notebook that opens on the right side of the topics are special notebooks for automated assessment by the playground. You cannot open a .py file on the right side, it would open in a new window.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

r = []
for i in range (5):
r[i]= int(input())
print (r)

what is wrong with this code?
it is throwing an error....list assingment index out of range

  Upvote    Share

Hi,

Would request you to share a screenshot of your code and the error that you are getting.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

try below:


r = []
for i in range(5):
x = int(input('Input value: '))
r.append(x)
print (r)

  Upvote    Share

hello sir please let me know about XP points and their uses.
One more thing, despite writing the correct answers, sometimes tit shows error for which i have to refer hints or answer which results in reducing XP points.

  Upvote    Share

Hi,

I am so sorry to hear that your XPs were deducted despite answering the questions correctly. Would request you to let us know when you know it is the correct answer but it is showing it has incorrect.

The XPs help you see the hints or answers as and when required.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

how to make 2D array

  Upvote    Share

Hi,

You can create a 2D array with the following code:

rows, cols = (5, 5)
arr = [[0]*cols]*rows
print(arr)
Please note that a 2D array is one which has more than 1 row and more than 1 column.
Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Thank you for reply sir,
Can you give me any example how exicute
I mean make any 2 D array please
i know for 2D array atleasr 2 either row or column

  Upvote    Share

Hi,

I have given the code to create a 2D array above. You can use that code in your Jupyter notebook to create a 2D array yourself.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

thank you sir i got it.

  Upvote    Share

hello sir what is meaning of return??

  Upvote    Share

Hi,

The *return* statement terminates the execution of a *function* and *returns* control to the calling *function*. Execution resumes in the calling *function* at the point immediately following the call. A *return* statement
can also *return* a value to the calling *function*.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

like end and it can also give some results

  Upvote    Share

Hi,

Python does not have an end command. It does have an exit command, however, that is different from return. You can use the exit command anywhere, however, return can only be used in a function. return, unlike exit, does not terminates the execution of the program. Rather it transfers the control to the main program that called the function.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

what is different between lambda fuction and def function?

  Upvote    Share

Hi,

*Lambda functions: *are operator can have any number of arguments, but it can have only one expression. It cannot contain any statements and it returns a function object which can be assigned to any variable. They can be used in the block they were created.

*def functions:* Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable. They can be called and used anywhere we want.
Hope that answers your queries.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Thank you sir

  Upvote    Share

Getting below error

404 : Not Found
You are requesting a page that does not exist!

If i try to open a existing notebook it opens in new tab.

  Upvote    Share

Hi,

Would request you to follow the method give in this link:
https://discuss.cloudxlab.c...
Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hello Sir,
what is the basic difference between following codes. Both are returns same. I can't understand

please explain

  Upvote    Share

Hi,

In the first example, you are getting a handle to both the key, and the value. However, in the second one you are only printing the key (the value gets printed automatically with it).

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hello Sir,
can I get github desktop for 32bit operating system?

  Upvote    Share

Hi Souvik,

Would request you to check the minimum requirements on the GitHub website and check if it matches your system.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

this file is not on github

  Upvote    Share

Hi,

The link to the codes in our repository are given just below the slides. Here's the link:

https://github.com/cloudxla...

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hi team,

The file their is not the same as been used in Video, the content is very less than that of the demo shown.

Please share that actual one with all example used for explaination.

  Upvote    Share

Hi,

Could you please let us know if there is any specific file that you found missing?

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

sir, what is the error?

  Upvote    Share

Hi Sumit,

Since you are using elif, the return command below that should be indented to the right.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Sir, one more question- what is error in following programming?
def print_even(n):
if n>0:
result=0
return result
result=result+2
return result
if result>n:
break
elif n==0:
return None

  Upvote    Share

Hi Sumit,

Are you getting any error with this code? If yes, then would request you to share a screenshot of your code and the error that you are getting,

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

sir, How I will get whatever you are typing in your jupyter notebook ?

  Upvote    Share

Hi Sumit,

As mentioned in the course, every code that we show here is there in our GitHub repository. You need to clone it here using the following command:
git clone https://github.com/cloudxla...

If you want, you can even fork it in your personal GitHub account.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

sir in which session lamda function is explained??

  Upvote    Share

Hi,

We do not have a separate session on lambda function, however, let me explain it for you. A lambda function is a small anonymous function. A lambda function can take any number of arguments, but can only have one expression.

Following are a couple of examples:

x = lambda a : a + 10

x = lambda a, b, c : a + b + C

x = lambda a, b : a * b

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hello Sir,
Why names call only first letter. Please explain?

  Upvote    Share

Hi,

This is because you are mentioning the first index by using [0].

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hello sir,
I am having confusion regarding conversion of list to dict & vise versa using buildin functions such as eg:
name=["a","b","c"]
name=dict(name)
please give me an example to solve such problems.
Thanks

  Upvote    Share

Hi,

You can convert a list into a dictionary like the following:

def Convert(a):
it = iter(lst)
res_dct = dict(zip(it, it))
return res_dct

# Driver code
lst = ['a', 1, 'b', 2, 'c', 3]
print(Convert(lst))

A list stores one element at a time, whereas a dictionary stores a key value pair. We need to keep that in mind while converting them.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hello sir,
can you please help me to solve this error it is not taking sq and cube as function,how to resolve it.
Thanks

  Upvote    Share

Hi,

You need to create a lambda function that would calculate the cube, and then pass that function as an argument to the function.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Append is used to add something to the list. So when i run program instead of append why it is calculating only the last enitity's value in the array.

  Upvote    Share

Hi, Nischal.

You are using retv=f(i), this for every for loop this will be going to update the variable retv and at last you will be only remaining with the last value that is 16.
But you would like to add every value to the list you need to use append retv.append(f(i)).
Now you will be getting all the squares of the elements inside the list.
All the best!

-- Satyajit Das

  Upvote    Share

ok thanks. That was helpful

  Upvote    Share

i want to know that when we use definite loop in iterating over a
file,then whenever we write word ,it iterate word by word and when we
write line,it iterates line by line.
my doubt is that how the loop came to know that how it should iterate?
do it came to know by just defining the variable name?

  Upvote    Share

Hello Disqus,

Thanks for contacting CloudxLab!

This automatic reply is just to let you know that we received your message and we’ll get back to you with a response as quickly as possible. During business hours (9am-5pm IST, Monday-Friday) we do our best to reply within a few hours. Evenings and weekends may take us a little bit longer.

If you have a general question about using CloudxLab, you’re welcome to browse our below Knowledge Base for walkthroughs of all of our features and answers to frequently asked questions.

- Tech FAQ <https: cloudxlab.com="" faq="" support="">
- General FAQ <https: cloudxlab.com="" faq=""/>

If you have any additional information that you think will help us to assist you, please feel free to reply to this email. We look forward to chatting soon!

Cheers,
The CloudxLab Team

  Upvote    Share

Hi Mohini,

If you look at the syntax of a loop statement, it itself contains the type it needs to loop with. For example, when we say

for val in array:
print(val)
we are already telling the loop that we need to iterate an array using it's basic component, which is it's elements. So when we tell the loop to iterate a line using it's basic elements, it understand that we want to loop using words. The syntax of the loop gives it that information.
Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

i am a creating a text file in jupyter but when trying to open a file fhandle=open('shashank.txt') it showing the below error
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-1-545e38d889aa> in <module>
----> 1 fhandle=open('shashank.txt')

FileNotFoundError: [Errno 2] No such file or directory: 'shashank.txt'

  Upvote    Share

i am not able to run %run first.py command...
it is showing error: ERROR:root:File `'first.py'` not found.

  Upvote    Share

Hi, Monika.

You can any python file from the terminal using command "python first.py ".
If you are using python3 version then python3 first.py.

All the best!

  Upvote    Share

how is (1,2,3) < (2,3) true?

  Upvote    Share

Hi, Karthik.
Tuple comparison is done elements by elements wise, if 1st is True, then it gives True. If rest is false then it is okay, but the first elements must be True then only True otherwise False.
try this (3,5,3) < (2,3,1) , (1,5,3) < (2,3,1) etc.
All the best!

  Upvote    Share

Are arguments passed to functions in python passed by value or passed by reference?

  Upvote    Share

def mymap(a,f):
r= [ ]
for i in a:
v=f(i)
r.append(v)
return r

mymap([2,3,5],lambda x:x*3)

its just giving [6],what is the error in code?

  Upvote    Share

Hi, Sourabh.

It is giving [6, 9, 15].
Can you rerun the code
v=f(i)
r.append(v) should be kept inside the for loop.

All the best!

  Upvote    Share

Thank you the issue that I reported earlier is resolved and I am able to access Jupyter

  Upvote    Share

Now I am getting Internal Server Error 500. How do I contact Admin to resolve this issue. Please help as I am unable to proceed with the course and loosing time. Thanks

  Upvote    Share

getting 502 Bad Gateway error while accessing the Jupyter notebook/ playground. Please help

  Upvote    Share

How t get the PPT in local file?

  Upvote    Share

I am not getting this Pyhon getting started file in my cloudx lab repository... please share.

  Upvote    Share

Hi, Vivek.

Here are the Cloudxlab github repository.
================================
1) https://github.com/cloudxla...
2) https://github.com/cloudxla...
3) https://github.com/singhabh...

All the best!

  Upvote    Share

def sqrtf(a,b):
rt=[]
for i in a:
v=b(i)
rt.append(v)
return rt
sqrtf([1,2,3,4],sq)

i am trying to use function inside a function but I am getting error , could you please help , below is the error

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-33-5b3a72ffd7ae> in <module>
5 rt.append(v)
6 return rt
----> 7 sqrtf([1,2,3,4],sq)

NameError: name 'sq' is not defined

  Upvote    Share

Hi, RK.

I understand that you are trying to find the square root of the list if number passed but you have not defined the sq, you need to write a separate logic for this. the you can pass this as argument.
Below code I have modified for you.

import math
def sqrtf(a):
rt=[]
for i in a:
v=math.sqrt(i)
rt.append(v)
return rt

All the best!

  Upvote    Share

t = 0
c = 0
while True:
no = eval(input('Enter a number: '))
if no == 'done':
break
x = float(no)
t = t + x
c = c+1

avg = t / c
print(avg)

NameError Traceback (most recent call last)
<ipython-input-8-c69b74cc7145> in <module>
2 c = 0
3 while True:
----> 4 no = eval(input('Enter a number: '))
5 if no == 'done':
6 break

<string> in <module>

NameError: name 'done' is not defined

  Upvote    Share

you can use intelligence on press "Tab" key.

  Upvote    Share

In the continuous lectures (say Python Foundation Course), there is too much of revision in the proceeding videos. Please avoid this, as this caters to a lot of confusions and difficult to point/track that from where exactly the new topics are starting. Divide these in 2 different videos if required. For a continuous learner its really difficult to cope up.

For E.g. - In video "Python Dictionary and Tuples" 1:30 hours of video covers the last session which is "Basic building blocks of Python". For a learner who is watching these videos continuously without a break becomes very redundant. Please try and avoid this.

Regards Pankaj

  Upvote    Share

Yes. I agree with you. Previously i have raised issue but no one has not response.

  Upvote    Share

Yes. It is diffiicult to pick up from where the lesson left off the last time. It is therefore taking more time than it should to complete a lesson.

  Upvote    Share

Hi, how to sort a list containing tuples.

  Upvote    Share

Hi Sandeep
Can we add null as key value in dictionary

  Upvote    Share

'None' can be added as a key value in dictionary. 'Null' can't be added as a key value in dictionary.

eg:
dictn = {'one': 4, None:2}
print(dictn)

a = dictn.get(None,0) + 1
a

Output :
{'one': 4, None: 2}
3

  Upvote    Share

name = input('Enter the file name: ')
handle = open(name)
text = handle.read()
words = text.split()

counts = dict()
for word in words:
counts[word] = counts.get(word, 0)+1

bigcount = None
bigword = None

for word.count in counts.items():
if bigcount is None or count > bigcount:
bigword = word
bigcount = count
print(bigword, bigcount)

after running above code on notebook
it is showing following error
Enter the file name: mbox.txt
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-17-cca6a4596c56> in <module>
1 name = input('Enter the file name: ')
----> 2 handle = open(name)
3 text = handle.read()
4 words = text.split()
5

FileNotFoundError: [Errno 2] No such file or directory: 'mbox.txt'

________

above file is present in Files Section

  Upvote    Share

Hi, Prashant.

Please check the correct path of the file.

All the best.

  Upvote    Share

plz guide on how to get the path

  Upvote    Share

did you get the reply

  Upvote    Share

Hi Sir, is there any difference when we use run simple.py and %run simple.py

  Upvote    Share

Hi Sai, In Jupyter, we can only use %run

  Upvote    Share

could you put mute when you drink or eat something?

  Upvote    Share

Hi Eduardo, thank you for a constructive feedback. The Instructor has been communicated to.

  Upvote    Share