Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Saroj Dhiman
/
python practice
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a9725774
authored
Nov 01, 2023
by
Saroj Dhiman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
this i do by init
0 parents
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
203 additions
and
0 deletions
file.py
practice.py
file.py
0 → 100644
View file @
a972577
File mode changed
practice.py
0 → 100644
View file @
a972577
#swap the elements in list, string, tuple, set and dictionary
# l1 = [2,3,4,5,6,7]
# l1[0] = l1[3]
# # print(l1)
# s = "this is great"
# # s = s.split()
# for i in range(3):
# for j in range(3):
# s[i] = s[j]
# print(s)
# s = {3,4,5,6}
# s = (3,4,5) #in tiple indexing is possible but not in sets
# print(s[1])
#string rotation
# s = "this"
# n = int(len(s)/2)
# print(s[n:]+s[:n])
# removing digits from string
# s = "alpha23"
# s1 = ""
# l = []
# for i in s:
# if i.isnumeric():
# l.append(i)
# else:
# s1+=i
# print(s1)
# example of picking
# import pickle
# with open("piko.txt",'bw') as file:
# k = "this is my brain!"
# pickle.dump(k,file)
# l = [34,56,12,21,23]
# for i in range(len(l)):
# for j in range(len(l)):
# if l[i]>l[j]:
# l[i],l[j] = l[j],l[i]
# print(l)
# l1 = [4,5,6,7]
# l2 = [8,9,2,1]
# l4 = list(zip(l1,l2))
# print(l4)
# l3 = [i+j for i,j in zip(l1,l2)]
# print(l3)
#star pattern
# for i in range(5):
# print(" "*(4-i),"*"*(i*2+1),end = " ")
# print()
# remove duplicacy from string
# s = "thisismypen"
# s1 = ""
# l = ""
# for i in s:
# if i not in l:
# l+=i
# else:
# s1+=i
# print(s1,l)
# vowel detection
# v = "aeiou"
# w = ""
# n_w = ""
# s = "thisisgreat"
# for i in s:
# if i in v:
# n_w+=i
# else:
# w+=i
# print(w,n_w)
# odd even characters in a string
# s = "this is my car"
# for i in s:
# if i == "i":
# s=s.replace(i,"new")
# print(s)
# replacement in a list
# l = [3,4,5,6,7]
# for i in range(len(l)):
# if l[i] == 3:
# l[i] = 67
# print(l)
# detecting the index number of a element
# l = [5,6,7,8]
# for i in l:
# if i == 7:
# print(l.index(i))
# d = {"saroj":1,"saroj":2}
# print(d)
# count particular element in a list
# l = [3,4,5,6,3,4,5,3,3,33,3]
# count = 0
# for i in range(len(l)):
# if l[i] == 3:
# l[i] = 6789
# print(l)
#reverse a list
# l = [4,5,6,7,8,9]
# for i in range(len(l)):
# for j in range(len(l)):
# if l[i]>l[j]:
# l[i],l[j]=l[j],l[i]
# print(l)
# year = int(input("enter the year: "))
# if (year%4==0 and year%400==0) or year%100 !=0:
# print("yes year is leap year")
# else:
# print("year is not leap year")
# find the index number in a list
# l = [5,6,7,3,2]
# def finding_index_number(l,n):
# for i in l:
# if i == n:
# print(l.index(i))
# finding_index_number(l,7)
#check the number is square or not
# n = 4
# import math
# print(math.isqrt(n))
#decorators
# def decorators(function):
# def inside_function(string):
# function(string.upper())
# return inside_function
# @decorators
# def apply_dec(string):
# print(string[::-1])
# apply_dec("saroj")
# raising exception
# try:
# a = 3
# b = 0
# if b == 0:
# raise Exception("not divisible")
# except Exception as e:
# print(e)
# finally:
# print("code is fully execited")
# # odd and even numbers
# even = [i for i in range(10) if i%2==0]
# odd = [i for i in range(10) if i%2!=0]
# print(even)
# print(odd)
# x = lambda w : w**2
# print(x(3))
# l = [5,6,7,3,1,423,1]
# min = l[0]
# max = l[0]
# for i in range(len(l)):
# if l[i]> max:
# max = l[i]
# if l[i]<min:
# min = l[i]
# print(min,max)
# k = 10
# l = [6,4,6,4,8,2,10,0,7,3,11,-1]
# for i in l:
# for j in l:
# if l[i]+l[j]==k:
# print(l[i],l[j])
# make a dictionary of two lists
# l1 = [4,5,6,7]
# l2 = [8,9,7,6]
# d = dict(zip(l1,l2))
# print(d)
# def factorial(n):
# if n<=1:
# return 1
# else:
# return n*factorial(n-1)
# print(factorial(5))
#printing fibbonaci series
# def febbonaci_series(n):
# if n<=1:
# return 1
# else:
# return febbonaci_series(n-1) + febbonaci_series(n-2)
# for i in range(10):
# print(febbonaci_series(i))
# # genrator
# def genrator():
# for i in range(1,10):
# yield i
# g = genrator()
# print(g.__next__())
# import os
# l = ["sar","sa"]
# s = os.path.commonprefix(l)
# print(s)
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment