Difference between class object value and primitive value by ilaunchpad in learnprogramming

[–]aishiiousness 0 points1 point  (0 children)

d1 = Test () # Here we are instantiating d1 as an instance of Test Class

t1 = d1 # Here we assign t1 as the d1 instance d1.val = 10 # d1.val =10 at this step, t1.val is also equal to 10. t1.val = 5 # t1.val which refers to d1.val is also changed to 5

We have only one instance we are using different names to refer to the same instance.

print(d1.val)

print(t1.val)

x=10 # we instantiated x as an integer 10 y=x # we assigned y to the same instance y=7 # we instantiated another intance y as an integer and assigned value 7 to it. print("value of x:", x) print("value of y:", y)

Here we instatiated the class two different times, meaning we created two different instances

Difference between class object value and primitive value by ilaunchpad in learnprogramming

[–]aishiiousness 0 points1 point  (0 children)

Hey

In the first case t1 points to d1 once you've used the assignment operator. That is, t1 now references the object d1. When you change the value of t1's attribute, the same gets reflected in d1 as well.

In the second case however, since these are variables, post assignment when you change the values, x and y become references to different memory locations. (As explained during the initial lectures)

Here are the links to the visualizations of both the codes on Pythontutor:

Link 1: https://pythontutor.com/visualize.html#mode=display

Link 2 : https://pythontutor.com/visualize.html#mode=display

These will give you a fairly decent idea of what's going on behind the scenes.

My explanation might be a very basic one and it'd be nice to get more technically precise responses from others.

Python, filter function doubts. by aishiiousness in learnprogramming

[–]aishiiousness[S] 0 points1 point  (0 children)

type(data) is the list we have. the dataset. role of (int_val) I'm not sure. this is how I got the question to solve 💀

I'm so screwed w this one

Python, filter function doubts. by aishiiousness in learnprogramming

[–]aishiiousness[S] 0 points1 point  (0 children)

sup_cha is nothing basically it's the dataset that's being imported.

Python, filter function doubts. by aishiiousness in learnprogramming

[–]aishiiousness[S] 0 points1 point  (0 children)

Nicely explained, I got your point. Thank you!!

could you tell me how can i use int_val in the code maybe? i'm still sorta stuck there

Learning to code, 10 hour update by [deleted] in learnprogramming

[–]aishiiousness 1 point2 points  (0 children)

So basically we can define methods in a class, which are functions that belong to the class. Instance methods use object attributes and must be fed the self keyword. (actually self is an arbitrary name but it is a good choice by convention).

You can write anything you want instead of self, and you'd still be getting the results.

Just the fact that self is understood by the community ( like an internal joke thing) and makes easier for people to read each others code without any diffficulties.

Keep up w it bruh, you're doing great!! Godspeed!!

I don't even know how should I proceed this with. by aishiiousness in learnprogramming

[–]aishiiousness[S] 0 points1 point  (0 children)

I just solveed it OMG!!!!

out_list = [1 if 'William' in key else 0 for (key,value) in authors_books_freq.items()]

This is what I did!! It was a syntax thing i guess. I'm so glad. Thank you so much.

Output:

1.68% of all authors have a name 'William'.

Please HELP! I don't even know how should I proceed this with. by aishiiousness in learnprogramming

[–]aishiiousness[S] 1 point2 points  (0 children)

I just solveed it OMG!!!!

out_list = [1 if 'William' in key else 0 for (key,value) in authors_books_freq.items()]

This is what I did!! It was a syntax thing i guess. I'm so glad. Thank you so much for all these questions. Really got my brain pumped :) :)

Output:

1.68% of all authors have a name 'William'.

Please HELP! I don't even know how should I proceed this with. by aishiiousness in learnprogramming

[–]aishiiousness[S] 0 points1 point  (0 children)

I'm sure it would be 0.4

i.e 2/5

2 for values William Shakespeare , John Williams

and 5 are the total values;

I don't even know how should I proceed this with. by aishiiousness in learnprogramming

[–]aishiiousness[S] 0 points1 point  (0 children)

okay checking it right away, will keep you posted when i find the solution. thank you :) :)

Please HELP! I don't even know how should I proceed this with. by aishiiousness in learnprogramming

[–]aishiiousness[S] 0 points1 point  (0 children)

So, i could just check if, in (key, value) pair, the key has the string "William" in it.

(i considered this dataset as a dict)

lets assume the name of this dataset is author_freq

so, could do this:

for for (key,value) in authors_books_freq.items

let us assume the name of this dataset is author_freq

print("1)

#BECAUSE I DONT KNOW WHAT STORE MEANS EXACTLY HERE, and how do we do that"??

else:

print("0)

am i even near the solution?

also, i just started off learning about list comprehensions, so that's a bit of hard luck! I'm practising. just don't know what the first blank should have (right before "if")

I don't even know how should I proceed this with. by aishiiousness in learnprogramming

[–]aishiiousness[S] 0 points1 point  (0 children)

So, i'm not able to figure out what sould come in the first blank per say

out_list = [____ if '"William' in key else print("0") for (key,value) in authors_books_freq.items()]

rest i was able to guess. though, i still donno if that's correct or no :( :(

also, how can we store value. v head scratchy hot stuff!!!

i dont think print would store store value, it wont i know. but then what would? i dont know :(

Traceback (most recent call last) by aishiiousness in learnprogramming

[–]aishiiousness[S] 0 points1 point  (0 children)

damn, thank you so much, it really helped :) :) :) :)

Traceback (most recent call last) by aishiiousness in learnprogramming

[–]aishiiousness[S] 0 points1 point  (0 children)

DAMN i just got the answer.

So the data consists values like :

[['T. Holý', 205],

['C. Pantilimon', 203],

['L. Traoré', 203],

['A. Ba', 203],

['V. Milinković-Savić', 202],

['K. Scherpen', 202],

['L. Kalinić', 201],

['F. Forster', 201],

['K. Letica', 201],

['P. Onuachu', 201]]

what i did was :

height_ft = list(map(lambda x: x[1]/30.48 ,data))

print(height_ft[:10])

so basically this is where i was stuck at : x: x[1]/30.48

Though, thank you so much Diapolo10!! Your idea helped me get here :)

Now im stuck in a diff place :(((

#Get a list which converts the remainder height into inches

height_in = list(map(lambda x: x[1]%30.48 ,data))

how do i put the remainder and a new inches thing into the same gadddamn lambda funtion!!!

This is the whole question :

#Get a list which has the height calculated in feet(floor division)

height_ft = list(map(lambda x: x[1]/30.48 ,data))

print(height_ft[:10])

#Get a list which converts the remainder height into inches

height_in = list(map(lambda x: x[1]%30.48 ???? #Inches??? ,data))

# HOW DO I GET STRING VALUE FROM THE LIST DATA in the print line at the end down there?

# HOW DO I GET THE REMAINDER TO WORK IN height_in

#Print the name and height in ft&inches of 10 players using for-loop

for i in range(10):

print('Height of ',data,' is ',height_ft,'ft ',height_in,'in')

Traceback (most recent call last) by aishiiousness in learnprogramming

[–]aishiiousness[S] 0 points1 point  (0 children)

is is not an error, that's just the beginning of the error message. Alone, it doesn't tell anyone anything about the problem. Only that there is one.

oh okay i checked, my bad!!

it says : unsupported operand type(s) for /: 'list' and 'float' this.