I have taken up many paid and unpaid python courses from a number of popular programs out there but never got this much clarity and understanding on list comprehension. Your method of teaching with so many real time scenarios is truly exceptional. The content is pure gold. Underrated channel. Thank you so much Sumit Sir! looking forward to the upcoming session
Hi Sumit Sir , I just love the way you are teaching. I have seen many youtube videos on python but this python course is unique.the content of this course helps me a lot to understand many concepts of python. Please share some more concepts of python which will help data engineers like us. Really you are a great teacher 🙏 Thanks a lot.
Solution to Assignment3(my tiny contribution). Im using defaultdict(), a subclass of Dictionary. I find it handy when working with lists. from collections import defaultdict company_average = defaultdict(list) for sublist in company: company_average[sublist[2]].append(sublist[3]) average_salaries = {department: sum(salaries) / len(salaries) for department, salaries in company_average.items()} print(average_salaries)
it was fun to know & see the benefits of List comprehension & various other concepts of Python, had little hesitancy to learn one another programming language, now i can embrace Python after seeing it is easy to learn from this Python series & also more importantly apply it in Pyspark code :)
Videos are really helpful. I have not seen such videos with real time examples. i am truly enjoying the sessions. Sir is it possible to create video for oops concepte.
Assignment 3 solution using list comprehension - dept_lst = [emp[2] for emp in emp_lst] dept_set = set(dept_lst) avg_lst = [[dept, sum([emp[3] for emp in emp_lst if emp[2] == dept])/len([x[2] for x in emp_lst if x[2] == dept])] for dept in dept_set]
Incredible, i enjoyed thoroughly. Just one question sir when we are doing word count, do you really feel we need to remove duplicate first? For example a paragraph may certain words which were repeated. If we remove duplicates then it will not give the result which we are looking for. Please share your thoughts on this
Hi Sumit Sir we are saying tuple is immutable but tuple inside list is mutable is that correct. for Ex i/p[(100,5),(200,10)] o/p[(100,5,105),(200,10,220)]
Below is the solution for 3rd question, Please suggest your improvements as this looks very complex to me dept_list=[i[2] for i in data] dept_set=set(dept_list) dept_count=[(i,dept_list.count(i)) for i in dept_set] print(dept_count) dept_sum=[ (j[2],j[3]) for i in dept_set for j in data if j[2]==i] print(dept_sum) for i in dept_count: count = 0 sum = 0 for j in dept_sum: if i[0]==j[0]: count += 1 sum+=j[1] if i[1]==count: avg=sum/count print(f'{i[0]}:Averege salary {avg}')
Assignment 2 solution : d=defaultdict(int) for i in trans: status=i[2] d[status]+=1 for a,b in d.items(): print(a,b) Assignment 3 solution : department_salary_sum = defaultdict(int) department_employee_count = defaultdict(int) for _,_,dept,salary in list1: department_salary_sum[dept] += salary department_employee_count[dept] += 1 avg={dept:department_salary_sum[dept]/department_employee_count[dept] for dept in department_salary_sum } for dept, avg_salary in avg.items(): print(f"{dept}: {avg_salary:.2f}")
Hello Sumit Sir, Just finished watching all the 4 video in your Python playlist, which are super insightful, just wanted to thank you for starting this course (for free) which will be beneficial for every student/employee. I have just finished the assignments that you mentioned at the end of this session, it was quite fun to solve did find the average salary one a bit tough but did not look for solution on GPT and gave it a shot and I am glad that I was able to solve it.🙂
Assignement 1: for word in line_set: result_set.append((word,lines.count(word))) print(result_set) for the above code im getting the below code, [('COMPLETE', 4)] [('COMPLETE', 4), ('PENDING_PAYMENT', 3)] [('COMPLETE', 4), ('PENDING_PAYMENT', 3), ('CLOSED', 2)] [('COMPLETE', 4), ('PENDING_PAYMENT', 3), ('CLOSED', 2), ('PROCESSING', 1)] Please let me know how to get the last row alone?
print(result_set) is under for loop. Its an indenting issue. Below updated code will give you the desired result. for word in line_set: result_set.append((word,lines.count(word))) print(result_set)
I have taken up many paid and unpaid python courses from a number of popular programs out there but never got this much clarity and understanding on list comprehension. Your method of teaching with so many real time scenarios is truly exceptional. The content is pure gold. Underrated channel. Thank you so much Sumit Sir! looking forward to the upcoming session
Great to hear!
Hi Sumit Sir , I just love the way you are teaching. I have seen many youtube videos on python but this python course is unique.the content of this course helps me a lot to understand many concepts of python. Please share some more concepts of python which will help data engineers like us.
Really you are a great teacher 🙏
Thanks a lot.
Best teacher in india 😊🎉
thank you for tour kind words
for the world💌
Sir. Also please teach OS module and how to handle excel files. I love the way you teach.
Solution to Assignment3(my tiny contribution). Im using defaultdict(), a subclass of Dictionary. I find it handy when working with lists.
from collections import defaultdict
company_average = defaultdict(list)
for sublist in company:
company_average[sublist[2]].append(sublist[3])
average_salaries = {department: sum(salaries) / len(salaries) for department, salaries in company_average.items()}
print(average_salaries)
that's great
how can i learn to implement logic like you sir BTW your videos are too good 😃
it was fun to know & see the benefits of List comprehension & various other concepts of Python, had little hesitancy to learn one another programming language, now i can embrace Python after seeing it is easy to learn from this Python series & also more importantly apply it in Pyspark code :)
Hey guys,
Sharing my approach which I used to solve the Assignments that Sumit Sir mentioned in the session
Assignment-1:
status_list = ['CLOSED', 'PENDING_PAYMENT', 'COMPLETE', 'CLOSED', 'COMPLETE', 'COMPLETE', 'COMPLETE', 'PROCESSING', 'PENDING_PAYMENT', 'PENDING_PAYMENT']
status_list_set = set(status_list)
print(status_list_set)
order_status_count = [(status,status_list.count(status)) for status in status_list_set]
print(order_status_count)
Assignment-2:
order_list = [
[1, 100, 'success'],
[2, 200, 'pending'],
[3, 150, 'success'],
[4, 300, 'failed'],
[5, 400, 'success'],
[6, 250, 'pending'],
[7, 350, 'failed'],
[8, 450, 'success'],
[9, 500, 'pending'],
[10, 600, 'failed']
]
order_list_status = [orders[2] for orders in order_list]
order_list_status_set = set(order_list_status)
status_count = [(status, order_list_status.count(status)) for status in order_list_status_set]
for status in status_count:
print(f"{status[0]} : {status[1]}")
Assignment-3:
employee_salary = [
[101, 'John', 'IT', 60000],
[102, 'Alice', 'HR', 50000],
[103, 'Bob', 'Finance', 70000],
[104, 'Emma', 'IT', 55000],
[105, 'David', 'Finance', 75000],
[106, 'Sophia', 'HR', 48000]
]
finance_sal=[]
it_sal = []
hr_sal = []
for item in employee_salary:
if item[2] == "IT":
it_sal.append(item[3])
elif item[2] == "HR":
hr_sal.append(item[3])
else:
finance_sal.append(item[3])
finance_avg_sal = sum(finance_sal)/len(finance_sal)
hr_avg_sal = sum(hr_sal)/len(hr_sal)
it_avg_sal = sum(it_sal)/len(it_sal)
print(f"Finance: Average Salary - {finance_avg_sal}")
print(f"IT: Average Salary - {it_avg_sal}")
print(f"HR: Average Salary - {hr_avg_sal}")
Please feel free to add any suggestions you have or any doubts that you need to clarify, I am happy to help.
One problem with this solution is that this code needs to change when the input has more departments, so this is not a generic solution
Best video on lists and tuples!
Yay! Thank you!
Sir we want same type of in depth lectures/playlist on
Excel & power BI for Data Analyst
with real industry relevant projects
😊
Top notch content sir, really loved it.
please upload videos as fast as you can.
Thanks
glad that you enjoyed the session
Very clear and super helpful examples taken
Glad it was helpful!
🔥🔥🔥🔥🔥🔥🔥🔥 on fire content .... many thanks Sumit Sir .... i am a bit late but catching up on all the videos in this playlist
Videos are really helpful. I have not seen such videos with real time examples. i am truly enjoying the sessions. Sir is it possible to create video for oops concepte.
nested_lists=[[i,i**2,i**3] for i in range(1,4)]
print(nested_lists)
please share running notes
dep_avg_sal = []
emp_department = [ emp[2] for emp in employees ]
emp_set = set(emp_department)
for emp_dep in emp_set:
count = 0
total_sum = 0
for dep_sal in employees:
if dep_sal[2] == emp_dep:
total_sum += dep_sal[3]
count += 1
sal_avg = total_sum / count
dep_avg_sal.append((emp_dep, sal_avg))
print(dep_avg_sal)
Sir, if I want to take a value during run time and want to add it within the nested list, Can it be possible with list comprehension??
Assignment 3 solution using list comprehension -
dept_lst = [emp[2] for emp in emp_lst]
dept_set = set(dept_lst)
avg_lst = [[dept, sum([emp[3] for emp in emp_lst if emp[2] == dept])/len([x[2] for x in emp_lst if x[2] == dept])] for dept in dept_set]
This is working perfectly, Thank you
For that 3rd assignment it will be very helpful if you can share the solution sir.
Incredible, i enjoyed thoroughly. Just one question sir when we are doing word count, do you really feel we need to remove duplicate first? For example a paragraph may certain words which were repeated. If we remove duplicates then it will not give the result which we are looking for. Please share your thoughts on this
input_list = ['CLOSED', 'PENDING_PAYMENT', 'COMPLETE', 'CLOSED', 'COMPLETE', 'COMPLETE', 'COMPLETE', 'PROCESSING', 'PENDING_PAYMENT', 'PENDING_PAYMENT']
status_cnt = [(status,input_list.count(status)) for status in input_list]
print(status_cnt) #[('CLOSED', 2), ('PENDING_PAYMENT', 3), ('COMPLETE', 4), ('CLOSED', 2), ('COMPLETE', 4), ('COMPLETE', 4), ('COMPLETE', 4), ('PROCESSING', 1), ('PENDING_PAYMENT', 3), ('PENDING_PAYMENT', 3)]
unique_status_cnt = list(set(status_cnt))
print(unique_status_cnt) #[('COMPLETE', 4), ('PENDING_PAYMENT', 3), ('CLOSED', 2), ('PROCESSING', 1)]
O/P:
[('COMPLETE', 4), ('PENDING_PAYMENT', 3), ('CLOSED', 2), ('PROCESSING', 1)]
Removing duplicate first--> gives wrong output
input_list = ['CLOSED', 'PENDING_PAYMENT', 'COMPLETE', 'CLOSED', 'COMPLETE', 'COMPLETE', 'COMPLETE', 'PROCESSING', 'PENDING_PAYMENT', 'PENDING_PAYMENT']
input_list_unique =list(set(input_list)) #removed duplicates
status_cnt = [(status,input_list_unique.count(status)) for status in input_list_unique]
print(status_cnt) #[('COMPLETE', 1), ('CLOSED', 1), ('PENDING_PAYMENT', 1), ('PROCESSING', 1)]
O/P:
[('COMPLETE', 1), ('CLOSED', 1), ('PENDING_PAYMENT', 1), ('PROCESSING', 1)]
Wonderful as expected...
Assignment 3:
seta = set()
for sublist in employee:
seta.add(sublist[2])
lista = list(seta)
print(lista)
IT =[]
HR =[]
Finance =[]
for sublist in employee:
if sublist[2] == lista[0]:
IT.append(sublist[3])
elif sublist[2] == lista[1]:
HR.append(sublist[3])
else:
Finance.append(sublist[3])
print("IT :%.2f"%(sum(IT)/len(IT)))
print("HR :%.2f"%(sum(HR)/len(HR)))
print("Finance :%.2f"%(sum(Finance)/len(Finance)))
could you pls make a video on cicd pipeline, agile methodology
It was great learning ❤
Hello sir, where are you putting notes for viewers?
@Sumit Mittal
Hi Sumit Sir we are saying tuple is immutable but tuple inside list is mutable is that correct.
for Ex i/p[(100,5),(200,10)] o/p[(100,5,105),(200,10,220)]
Below is the solution for 3rd question, Please suggest your improvements as this looks very complex to me
dept_list=[i[2] for i in data]
dept_set=set(dept_list)
dept_count=[(i,dept_list.count(i)) for i in dept_set]
print(dept_count)
dept_sum=[ (j[2],j[3]) for i in dept_set for j in data if j[2]==i]
print(dept_sum)
for i in dept_count:
count = 0
sum = 0
for j in dept_sum:
if i[0]==j[0]:
count += 1
sum+=j[1]
if i[1]==count:
avg=sum/count
print(f'{i[0]}:Averege salary {avg}')
Hi Sumit sir
Are you going to cover data libraries like PANDAS and NUMPY as part of these sessions later ?
yes I will cover
Thank You Sir
@@sumitmittal07 sir when will be the next video on Python
Hello sir, where are you putting notes for viewers?
Assignment 2 solution :
d=defaultdict(int)
for i in trans:
status=i[2]
d[status]+=1
for a,b in d.items():
print(a,b)
Assignment 3 solution :
department_salary_sum = defaultdict(int)
department_employee_count = defaultdict(int)
for _,_,dept,salary in list1:
department_salary_sum[dept] += salary
department_employee_count[dept] += 1
avg={dept:department_salary_sum[dept]/department_employee_count[dept] for dept in department_salary_sum }
for dept, avg_salary in avg.items():
print(f"{dept}: {avg_salary:.2f}")
Sir please help with assignment 3
Hello Sumit Sir,
Just finished watching all the 4 video in your Python playlist, which are super insightful, just wanted to thank you for starting this course (for free) which will be beneficial for every student/employee. I have just finished the assignments that you mentioned at the end of this session, it was quite fun to solve did find the average salary one a bit tough but did not look for solution on GPT and gave it a shot and I am glad that I was able to solve it.🙂
I am really happy to hear this
Thank you @@sumitmittal07 Sir. For the assignment solutions I just wanted some of your thoughts and the community so should I share it here?.
Hi Can you please share reference theory material and python files? You mentioned in few videos that its available but I couldn't find it
Sir How many videos in total does it take to complete the
python playlist
total 10 in this playlist
someone please share solution of assignment 3 using list comprehension
Assignement 1:
for word in line_set:
result_set.append((word,lines.count(word)))
print(result_set)
for the above code im getting the below code,
[('COMPLETE', 4)]
[('COMPLETE', 4), ('PENDING_PAYMENT', 3)]
[('COMPLETE', 4), ('PENDING_PAYMENT', 3), ('CLOSED', 2)]
[('COMPLETE', 4), ('PENDING_PAYMENT', 3), ('CLOSED', 2), ('PROCESSING', 1)]
Please let me know how to get the last row alone?
print(result_set) is under for loop. Its an indenting issue. Below updated code will give you the desired result.
for word in line_set:
result_set.append((word,lines.count(word)))
print(result_set)
😃😃
Anyone got notes ???
Devin ko sab aata h
Anyone got notes please share 🙏
👏👏🫰
dep_list=[(1,'JOHN','IT',2000),(2,'sam','IT',2000),(3,'RAM','HR',3000)]
dep_list_new=
[(line[2],line[3]) for line in dep_list] //[('IT', 2000), ('IT', 2000), ('HR', 3000)]
dept_salaries = {} //empty_dict
[dept_salaries.setdefault(dept, []).append(salary) for dept, salary in dep_list_new]//{'IT': [2000, 2000], 'HR': [3000]}
average_salaries = {dept: sum(salaries) / len(salaries) for dept, salaries in dept_salaries.items()}
print(average_salaries)