0% found this document useful (0 votes)
210 views3 pages

4

The document contains Python code snippets for various list operations and problems: 1) Finding the sum, largest number, common numbers between lists, even numbers from a list, separating even and odd numbers from a list. 2) Removing repeated elements from a list, finding the longest word in a sentence, counting occurrences of a number. 3) Printing website suffixes from a list of URLs. 4) Sorting a list of numbers in ascending and descending order without using the sort() function.

Uploaded by

sainaveen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
210 views3 pages

4

The document contains Python code snippets for various list operations and problems: 1) Finding the sum, largest number, common numbers between lists, even numbers from a list, separating even and odd numbers from a list. 2) Removing repeated elements from a list, finding the longest word in a sentence, counting occurrences of a number. 3) Printing website suffixes from a list of URLs. 4) Sorting a list of numbers in ascending and descending order without using the sort() function.

Uploaded by

sainaveen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#Write a python program to find the sum of all numbers in a list

"""a = [1,2,3,4,5,6,7,8,9,10]
sum = 0
for x in a:
sum = sum+x
print(sum)"""

#Write a python program to find largest number in a given list with out using max()
"""a = [1,2,22,3,45,666]
lnum = 0

for x in a:
if x > lnum:
large = x
lnum = large
print(lnum)"""
# Write a python program to find the common numbers from two lists

"""a = [1,2,3,4,22,33,44,6,7,88]
b = [1,22,44,7,8,88]
c =[]

for x in a:
if x in b:
c.append(x)
print(c)"""

#Write a python program to print all even numbers from a given list

"""a = [1,2,3,4,5,6,7,8,9,10]

for x in a:
if x%2 == 0:
print("even numbers",x)"""
#Write a python program to create a list of even numbers and another list of odd
numbers from a given list

"""a = [1,2,3,4,5,6,7,8,9,10,11,19,22,55,3,]
b =[]
c =[]

for x in a:
if x%2 == 0:
b.append(x)
else:
c.append(x)
print("odd number:",c)
print("even numbers:",b)"""

#=================================================

#Write a python program to remove repeated elements from a given list without using
built-in methods

"""a = [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,10,10]
b =[]
for x in a:
if x not in b:
b.append(x)
print(b)"""

# Write a python program to find the longest word in a given sentence

"""a = "i love my india"


b = a.split()
large= 0
large_w = 0

for x in b:
if len(x)>large:
large_w = x
large = len(x)
print(large_w)
print(x," ",len(x))"""

#Write a python program to find number of occurrences of given number with out
using built-in methods

"""a = int(input("enter the number"))


b = [10,20,30,40,10,20,30,40,10,20,6,6,6]
count =0

for x in b:
if x == a:
count = count+1
print(count)"""

#["www.zframez.com", "www.wikipedia.org", "www.asp.net", "www.abcd.in"]

#Write a python program to print website suffixes (com , org , net ,in) from this
list
"""a = ["www.zframez.com", "www.wikipedia.org", "www.asp.net", "www.abcd.in"]
b = a[0]
c = a[1]
d = a[2]
e = a[3]
f = b.split(".")
g = c.split(".")
h = d.split(".")
i = e.split(".")
for x in f:
print(f[2],",",end=" ")
break
for x in g:
print(g[2],",",end= " ")
break
for x in h:
print(h[2],",",end= " ")
break
for x in i:
print(i[2])
break"""

#Write a python program to sort a given list of numbers with out using sort()
function

#ascending to descending order:


"""a =[1,44,77,5,2,4,88,0,4,1,11,7]
b= a[0]
c = []

while len(a)>0:
temp = min(a)
c.append(temp)
a.remove(temp)
print(c)"""

#descending order to asending order:


"""a=[1,44,77,5,2,4,88,0,4,1,11,7]
b =a[0]
c =[]
while len(a)>0:
temp = max(a)
c.append(temp)
a.remove(temp)
print(c)"""

You might also like