Skip to content

Commit

Permalink
added list exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
amantiwari8861 committed Jan 12, 2024
1 parent 6470218 commit a99119f
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.analysis.typeCheckingMode": "basic",
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.formatting.provider": "none"
}
11 changes: 11 additions & 0 deletions 05 Collections/listexercise.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1.take 10 no. from user and find maximum number.
2.take 10 no. from user and find minimum number.
3.take 10 no. from user and take a number to search from list and find the index of that number.(linear search)
4.copy one list's elements to another list.
5.print list's elements in reverse order.
6.Write a python program to find the common elements between two lists of integers.
7.Write a python program to find the second largest element in an list.
8.Write a python program to test the equality of two lists.
9. Write a python program to find the number of even and odd integers in a given list of integers.
10.Write a python program to get the difference between the largest and smallest values in an list of integers.
11.Write a python program to find the unique elements in an list.
13 changes: 7 additions & 6 deletions Strings/Stringfxn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
str1="the quick.BRown fox JUMPS over the lazy frog"
# str1="the quick.BRown fox JUMPS over the lazy frog"

# length=len(str1)
# print("the sentence length is ",length)
Expand All @@ -12,6 +12,7 @@
# print(str1[::2])
# print(str1[4::2])
# print(str1[::-2])
# print(str1[::-1])
# print(str1.lower())
# print(str1.upper())
# print(str1.title())
Expand All @@ -20,8 +21,8 @@
# print(str1.islower())
# print(str1.count("fox"))
# print("@".join("Hii"))
strarr=str1.split(" ")
print(strarr)
print("-".join(strarr))
print(" ".join(strarr))
print("_".join(strarr))
# strarr=str1.split(" ")
# print(strarr)
# print("-".join(strarr))
# print(" ".join(strarr))
# print("_".join(strarr))
75 changes: 75 additions & 0 deletions numpy/1.numpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Importing NumPy
import numpy as np

# Creating Arrays:

# 1D array
arr_1d = np.array([1, 2, 3])
print("1D Array:")
print(arr_1d)

# 2D array
arr_2d = np.array([[1, 2, 3], [4, 5, 6]])
print("\n2D Array:")
print(arr_2d)

# Array with zeros
zeros_arr = np.zeros((3, 3))
print("\nArray with Zeros:")
print(zeros_arr)

# Array with ones
ones_arr = np.ones((2, 2))
print("\nArray with Ones:")
print(ones_arr)

# Array with a range of values
range_arr = np.arange(0, 10, 2)
print("\nArray with a Range:")
print(range_arr)

# Basic Operations:

# Addition
result_add = arr_1d + arr_1d
print("\nAddition Result:")
print(result_add)

# Multiplication
result_mul = arr_1d * 2
print("\nMultiplication Result:")
print(result_mul)

# Element-wise square root
result_sqrt = np.sqrt(arr_1d)
print("\nSquare Root Result:")
print(result_sqrt)

# Indexing and Slicing:

# Accessing element
element = arr_1d[0]
print("\nAccessing Element:")
print(element)

# Slicing
subarray = arr_1d[1:3]
print("\nSliced Subarray:")
print(subarray)

# Mathematical Functions:

# Sum of all elements
total_sum = np.sum(arr_1d)
print("\nSum of Elements:")
print(total_sum)

# Mean of elements
mean_value = np.mean(arr_1d)
print("\nMean of Elements:")
print(mean_value)

# Element-wise exponentiation
exp_arr = np.exp(arr_1d)
print("\nExponential of Elements:")
print(exp_arr)
58 changes: 58 additions & 0 deletions numpy/O level python syllabus.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
O level python syllabus

(i) Introduction to Programming

The basic Model of computation, algorithms, flowcharts, Programming
Languages, compilation, testing & debugging and documentation.

(ii) Algorithms and Flowcharts to Solve Problems

Flow Chart Symbols, Basic algorithms/flowcharts for sequential processing,
decision based processing and iterative processing. Some examples like:
Exchanging values of two variables, summation of a set of numbers, Decimal
Base to Binary Base conversion, Reversing digits of an integer, GCD (Greatest
Common Divisor) of two numbers, Test whether a number is prime, factorial
computation, Fibonacci sequence, Evaluate ‘sin x’ as sum of a series, Reverse
order of elements of an array, Find largest number in an array, Print elements of
upper triangular matrix, etc.

(iii) Introduction to Python

Python Introduction, Technical Strength of Python, Introduction to Python
Interpreter and program execution, Using Comments, Literals, Constants,
Python’s Built-in Data types, Numbers (Integers, Floats, Complex Numbers,
Real, Sets), Strings (Slicing, Indexing, Concatenation, other operations on Strings), Accepting input from Console, printing statements, Simple ‘Python’
programs.
(iv) Operators, Expressions and Python Statements

Assignment statement, expressions, Arithmetic, Relational, Logical, Bitwise
operators and their precedence, Conditional statements: if, if-else, if-elif-else;
simple programs, Notion of iterative computation and control flow –range
function, While Statement, For loop, break statement, Continue Statement, Pass
statement, else, assert.

(v) Sequence Data Types
Lists, tuples and dictionary, (Slicing, Indexing, Concatenation, other operations
on Sequence datatype),concept of mutability, Examples to include finding
the maximum, minimum, mean; linear search on list/tuple of numbers, and
counting the frequency of elements in a list using a dictionary.
(vi) Functions
Top-down approach of problem solving, Modular programming and functions,
Function parameters, Local variables, the Return statement, DocStrings, global
statement, Default argument values, keyword arguments, VarArgs parameters.
Library function-input(), eval(),print(), String Functions: count(), find(), rfind(),
capitalize(), title(), lower(), upper(), swapcase(), islower(), isupper(), istitle(),
replace(), strip(), lstrip(), rstrip(), aplit(), partition(), join(), isspace(), isalpha(),
isdigit(), isalnum(), startswith(), endswith(), encode(), decode(), String: Slicing,
Membership, Pattern Matching, Numeric Functions: eval(), max(), min(), pow(),
round(), int(), random(), ceil(), floor(), sqrt(), Date & Time Functions, Recursion.
(vii) File Processing
Concept of Files, File opening in various modes and closing of a file, Reading from
a file, Writing onto a file, File functions-open(), close(), read(), readline(),
readlines(),write(), writelines(),tell(),seek(), Command Line arguments.
(viii) Scope and Modules
Scope of objects and Names, LEGB Rule
Module Basics, Module Files as Namespaces, Import Model, Reloading Modules.
(ix) NumPy Basics
Introduction to NumPy, ndarray, datatypes, array attributes, array creation routines,
Array From Existing Data, Array From Numerical Ranges, Indexing & Slicing.
13 changes: 13 additions & 0 deletions temp/LoopControlStatement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
numbers=[10,20,30,40,78,346,238,40,99,78,346,238,40,78,346,238]
# #linear search
# key=int(input("enter no. to be searched:"))
# for i in range(len(numbers)):
# if key==numbers[i]:
# print(numbers[i],"found at postion",i,"in list.")
# break

for num in numbers:
if num==40:
continue
print("the element is",num)

24 changes: 24 additions & 0 deletions temp/Q1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def solve(S1, S2):
L1 = len(S1)
L2 = len(S2)
S = ['A'] * (L1 + L2 - 1)

for ind in range(L2):
if S2[ind] == 'T':
for ind2 in range(L1):
if S[ind + ind2] != S1[ind2]:
return -1
else:
for ind2 in range(L1):
if S[ind + ind2] == 'A':
S[ind + ind2] = S1[ind2]

return ''.join(S)

# Example Usage
S1 = "ABCA"
S2 = "TFFF"
result = solve(S1,S2)
print(result)

# Given a string S1 of length L1 Consisting of Latin uppercase alphabets only and a string S2 of length L2 consisting of haracters T and F only Generate a lexicographically smalIest string S of length (L1 + L2 - 1) such that a substring of length L1 in string starting at index i (0 <= i < L2) is equal to S1 if and only if ith element of S2 is T else not. If no such string can be generated, print -1 Notes: A string a is lexicographically smaller than a string b if and only if one of the following holds: • a is a prefix of b, but a !=b; • in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet then the corresponding letter in b. Find the lexicographically smallest string S which satisfies the given condition. Complete the solve function. This function takes the following 2 parameters and returns the answer. S1 Represents a string S1 S2 Represents a string S2 Input format for custom testing Note: Use this input format if you are testing against custom input or writing code The first line contains T, which represents the number of test cases. For each test case: The first line contains a string S1 The second line contains a string S2 Output format For each test case, print a string S in a new line or -1 if not possible.
39 changes: 39 additions & 0 deletions temp/list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# grogery=[]
# grogery=list()
# grogery=["vegetables","spices",True,10,3+2j,56.89,["milk","juice"],"fruits","etc"] #list of str
# print(grogery[0])
# print(type(grogery[0]))
# grogery.sort() #error
# print(grogery)
# print(type(grogery))

# for item in grogery:
# print(item,"of type",type(item))

# print(range(len(grogery)))

# for i in range(len(grogery)):
# print(grogery[i],"of type",type(grogery[i]))

# grogery.append("tea")
# print(grogery)

# numbers=[]
# numbers.append(10)
# print(numbers)
# numbers[0]=55
# print(numbers)

# noOfElements=int(input("enter no. of elements:")) # let noOfElement=5
# numbers=[] #empty list

# for i in range(noOfElements): #range(0,5)
# num=int(input("enter "+str(i)+"th number :"))
# numbers.append(num)

# print(numbers)

# numbers.sort()

# print("after sorting :",numbers)

71 changes: 71 additions & 0 deletions temp/listmanip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# itemlist=[] #empty list
# itemlist=["A","pulse","fruits",True,5.67883,78]

# print(itemlist)
# print(itemlist[0])
# print(type(itemlist[0])) # A

# itemlist.reverse()
# print(itemlist)

# fruits=["apple","","banana","chiku","pineapple","pomegranate","chiku","etc"]

# print(fruits[-2])
# print(fruits[3:])
# print(fruits[3:5])
# print(fruits[:-2])
# print(fruits[3:-2]) # [inclusive:exclusive]
# print(fruits[::-1]) # [inclusive:exclusive]
# print(fruits)
# fruits.append("custard apple")
# print(fruits)
# fruits.clear()
# fruits.reverse()
# print(fruits)
# print(len(fruits))
# noOfChiku=fruits.count("chiku")
# print(noOfChiku)

# print(fruits.count("chiku"))

# print(fruits.append("berry"))
# fruits.extend("mango")
# fruits.extend(["mango","mango 2.0","mango","mango 4.0"])
# fruits.extend({"mango","mango 2.0","mango","mango 4.0"})
# fruits.extend(("mango","mango 2.0","mango","mango 4.0"))
# fruits.insert(2,15)
# fruits.remove("")
# fruits.pop()
# fruits.pop()
# # fruits.sort()
# xyz=fruits.copy()
# print("XYZ : ",xyz)
# print(fruits)


# fruits=["Apple","mango"]
# # eatableitems=fruits
# eatableitems=fruits.copy()


# print("fruits :",fruits)
# print("eatableitems:",eatableitems)

# eatableitems.remove("mango")

# print("fruits :",fruits)
# print("eatableitems:",eatableitems)

# print(fruits.index("chiku"))
# print(fruits.index("chiku",4))

# print(fruits[0])
# print(fruits[1])
# print(fruits[2])

# for f in fruits:
# print("Fruit is :",f)

# print(range(len(fruits)))
# for i in range(len(fruits)):
# print("at index",i,"the fruit is",fruits[i])

0 comments on commit a99119f

Please sign in to comment.