Python Sets Are OP!! #python #programming #coding

preview_player
Показать описание

Background Music:
Creative Commons / Attribution 4.0 International (CC BY 4.0)
Рекомендации по теме
Комментарии
Автор

How to do task X on python:
Step 1: Call function that completes task X
Step 2: Return

gnxrly
Автор

Interviewer : get the hell out of my office

shreehari
Автор

"I wanna create a minecraft game"
Python: import minecraft

ultimatetroll_yt
Автор

The name "merge_arrays" is misleading: I would not have guessed that it removes duplicates and sorts the result.

slartidan
Автор

"arrayA" and "arrayB" hurt my python eyes

mjdryden
Автор

You should use the predefined functions like set.union(other set) as they are often defined in C and run faster

wyattboyer
Автор

c = sorted(set(a).union(set(b)))
print(c)

sepidehmohammadi
Автор

Camel case and snake case just in one line. Perfect😂😂😂

wowazzz
Автор

The way he was typing looked like he was Ctrl-Z-ing the entire time.

idontwantanamethx
Автор

instead of doing sorted(set(a + b)), would be better: sorted(set(a) & set(b))

salchigamer
Автор

Given the two arrays are sorted, we can create a custom merge function, similar to merge part of the merge sort algorithm. Also use a set ds to store the added array items and check before adding them in the merge function.

buildsome
Автор

Intersting to see how performant this is compared to manually making such function with loops, comparisons, and sorting

fuzzy-
Автор

Faster solution(I’m talking about time complexity here): union_set = set(array1).union(array2)
sorted_union = sorted(union_set)

gaethomari
Автор

correct me if i’m wrong but with the assumption both lists are sorted at the beginning, it should take linear time to remove duplicates, we just need to check the most recent non dupe, then run the merge operation from mergesort using priority queues, should give linear time (any dupes from an element being in both A and B can be removed in const time alteration to merge alg) giving linear time better than O(m+n)log(m+n)

rryt
Автор

So simple. 3 lines combined into a single line

nizarbreezoft
Автор

"Thank You that's enough, unfortunately you're not what we're looking for. Have a great day!"

AverageSensei
Автор

We can also use also inbuilt function to solve it ❤

darkshadow
Автор

Great tip.

When is your full Python tutorial dropping?

johnnycincocero
Автор

c = sorted(set(a + b)) with extra steps.

johnnysmith
Автор

Assuming arrays are sorted. Put 2 indexes at the beginning of these arrays, append element which is higher among arr1[id1] and arr2[id2], skip the element which is the same as last in resulting array, increment used index

O(n)

adefe.inside