for multiple duplicate elements: num=int(input()) l=[int(input()) for i in range(num)] orig=[] dup=[] for i in l: if i not in orig: orig.append(i) else: dup.append(i) print(l) print(orig) print(dup)
Is there a super efficient way to do this? I tried with panda and it takes about the same time. I'm dealing with lists of 100k elements. Any advice? I'd really appreciate it! Thanks!
Here you know the duplicate values and you added them in the if condition and got those indexes what if you dont the elements which got duplicated in such cases how to do.?
n = int(input("How many elements you want in list:")) list1 = [] for i in range(n): list1.append(eval(input())) print("input list is:",list1) elem = eval(input("select the element: ")) list2 = [i for i in range(len(list1)) if list1[i]==elem] print("index of",elem,"is:",list2) :)
l1=["alex","hannahe","james"] #to find out no of and e l2=[] a="" count=0 for i in range(0,len(l1)): a=l1[i] count=0 for j in range(0,len(a)): if a[j]=='a'or a[j]=='e': count=count+1 l2.append(count)
def dup_elmnt(list1): indx_list=[] temp=[] for j in list1: if list1.count(j)>=2 and j not in temp: for i in range(len(list1)): if list1[i]==j: indx_list.append(i) temp.append(j) else: pass return indx_list
i know that we can know the first occurence of the element by index method in lists,but can we do this same with because sets are unordered and unchangeable sometimes it prints only duplicate elements or without duplicate elements.like union( ) and update method exclude duplicate elements.
That program will print all the index of given duplicate element in list. 1 take a list with duplicate values. 2. we are using list comprehension method, i for i in range(len(list1)) ---------------------> it will print all the index of list element. but we want index of particular duplicate element, for example 1. so i will take if list1[i] == 1 condition. so it will give all the index duplicate element 1. 3 .next we will print that. :)
also how can i make money from python becouse i know python, java, c#,c++,c as well as javascript html and css(cascading style sheets).what can i do for passive income
It will work for any list. If you want to take user entered list then, instead of taking list directly take like this. num = int(input("enter the list length:")) list1 = [int(input()) for i in range(num)] :)
#finding the index for diplicate eliments l = [1,2,3,3,1,0,1] count = 0 s = set() v = [] for indx,value in enumerate(l): if value not in s: s.add(value) else: v.append([value,indx]) print(v)
Second Maximum Number in a List Description Given a list of numbers, find the second largest number in the list. Note: There might be repeated numbers in the list. If there is only one number present in the list, return 'not present'. Examples: Input 1: [7, 2, 0, 9, -1, 8] Output 1: 8 Input 2: [3, 1, 4, 4, 5, 5, 5, 0, 2, 2] Output 2: 4 Input 2: [6, 6, 6, 6, 6] Output 2: not present can you explain this problem
List1 = [ken, di, py] #firstname List2 = [py, thon, prog] #lastname List2 = [3,3,1] #grades How to get the max or min grades with getting the parralel index of list 1 and list2 My prob is only 0 index is readable But i need output is Ken py 3 Di thon 3
for multiple duplicate elements:
num=int(input())
l=[int(input()) for i in range(num)]
orig=[]
dup=[]
for i in l:
if i not in orig:
orig.append(i)
else:
dup.append(i)
print(l)
print(orig)
print(dup)
I really look forward to your videos as I think you're method of teaching is really good. Keep up , and please make video about Archive fils THANK YOU
Thank you :)
i was building a massive python bot and stuck in this simple algorithm!! XD But thanks sister! For Saving my time !!
Pleasure 😊
Dear sister your effort are very special. God bless you
You are teaching very good.Can you make video for this question:
Write user defined function to show scope of global and local variables. In python.
Nice it's really helpful and understandable...அருமை✨☺️
thank you so much you saved my project
Glad to hear that :)
i am quarantine at home, and next semester is my intern..so utilizing the time looking this type of your video..subscribed..make more video mam
Similar to me
Wow amazing superb your explanation is very clear👏👏👏
Thank you :)
beautiful and simple. just two lines.
Thank you :)
Thanks a lot for the explanation
you are genius
Thank you :)
can you please tell, How to perform same operation for nested in list...?
mam your are really good
Thank you :)
Is there a super efficient way to do this? I tried with panda and it takes about the same time. I'm dealing with lists of 100k elements. Any advice? I'd really appreciate it! Thanks!
Find them by hand manually
Thanks ❤
Here you know the duplicate values and you added them in the if condition and got those indexes what if you dont the elements which got duplicated in such cases how to do.?
Is it possible to print the multiple duplicate element's index at same time??
Thank you.
You're welcome! :)
nice question osm
You are good
Thank you :)
Thank you!!!
helloo.. can we add else statement to the above code??
Yes :)
Mam how can we make similar program when we input the list values from user and we don't know the repeated values
n = int(input("How many elements you want in list:"))
list1 = []
for i in range(n):
list1.append(eval(input()))
print("input list is:",list1)
elem = eval(input("select the element: "))
list2 = [i for i in range(len(list1)) if list1[i]==elem]
print("index of",elem,"is:",list2)
:)
@@AmulsAcademy thank you
names=['alex','hannahe','james']
Find how many 'e' and 'a' are there in list
output [2,3,2]
How to solve this one please asist??
l1=["alex","hannahe","james"]
#to find out no of and e
l2=[]
a=""
count=0
for i in range(0,len(l1)):
a=l1[i]
count=0
for j in range(0,len(a)):
if a[j]=='a'or a[j]=='e':
count=count+1
l2.append(count)
print(l2)
thnq ...
Welcome :)
I see you're hard coding the repeated
element in the code. But in most cases, we won't be knowing what was the repeated element.
def dup_elmnt(list1):
indx_list=[]
temp=[]
for j in list1:
if list1.count(j)>=2 and j not in temp:
for i in range(len(list1)):
if list1[i]==j:
indx_list.append(i)
temp.append(j)
else:
pass
return indx_list
i know that we can know the first occurence of the element by index method in lists,but can we do this same with because sets are unordered and unchangeable sometimes it prints only duplicate elements or without duplicate elements.like union( ) and update method exclude duplicate elements.
nice please tell me that which is the best laptop for programming and hacking
Can u make a program in python to check is user name valid or not
I will try :)
Please tell me, how it will be compiler run step by step
That program will print all the index of given duplicate element in list.
1 take a list with duplicate values.
2. we are using list comprehension method,
i for i in range(len(list1)) ---------------------> it will print all the index of list element.
but we want index of particular duplicate element, for example 1. so i will take if list1[i] == 1 condition.
so it will give all the index duplicate element 1.
3 .next we will print that.
:)
@@AmulsAcademy thank you
how do you do this in java?
also how can i make money from python becouse i know python, java, c#,c++,c as well as javascript html and css(cascading style sheets).what can i do for passive income
Work for google, or big companies that require such skills, most pay a huge salary, especially in the medical field.
This code will give index of non duplicate numbers also. Sloppy code
please do this for gerenal code
It will work for any list.
If you want to take user entered list then, instead of taking list directly take like this.
num = int(input("enter the list length:"))
list1 = [int(input()) for i in range(num)]
:)
hello every one i have a number = 963 but i want output like this 18 is it possible
num = int(input("num:"))
result=0
str_num = str(num)
for i in str_num:
result = result+int(i)
print(result)
:)
@@AmulsAcademy Thank you so much Amuls :)
@@AmulsAcademy wow first 2 min. i didnt understand
#finding the index for diplicate eliments
l = [1,2,3,3,1,0,1]
count = 0
s = set()
v = []
for indx,value in enumerate(l):
if value not in s:
s.add(value)
else:
v.append([value,indx])
print(v)
you have hardcoded the 1 its bad
Awesome
Thank you :)
Second Maximum Number in a List
Description
Given a list of numbers, find the second largest number in the list.
Note: There might be repeated numbers in the list. If there is only one number present in the list, return 'not present'.
Examples:
Input 1:
[7, 2, 0, 9, -1, 8]
Output 1:
8
Input 2:
[3, 1, 4, 4, 5, 5, 5, 0, 2, 2]
Output 2:
4
Input 2:
[6, 6, 6, 6, 6]
Output 2:
not present
can you explain this problem
I will try to make a video on that :)
List1 = [ken, di, py] #firstname
List2 = [py, thon, prog] #lastname
List2 = [3,3,1] #grades
How to get the max or min grades with getting the parralel index of list 1 and list2
My prob is only 0 index is readable
But i need output is
Ken py 3
Di thon 3