Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pandiarajan-src committed Jun 9, 2024
0 parents commit 1282b9a
Show file tree
Hide file tree
Showing 18 changed files with 1,827 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.DS_Store
/.venv
206 changes: 206 additions & 0 deletions concepts/list_samples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# Simple list examples
def print_items_in_list():
numbers = [1, 2, 3, 4, 5]
for num in numbers:
print(num, end=" ")

############

# https://www.programiz.com/python-programming/methods/list

numbers = [21, 10, 54, 12]

print("Before Append:", numbers)

# using append method
numbers.append(32)
numbers.append(9)
print("After Append:", numbers)

prime_numbers = [2, 3, 5]
print("List1:", prime_numbers)

even_numbers = [4, 6, 8]
print("List2:", even_numbers)

prime_numbers.extend(even_numbers) # list1.extends(list2)

print("List after append:", prime_numbers)

languages = ['Python', 'Swift', 'C++']

languages[2] = 'C'

print(languages) # ['Python', 'Swift', 'C']

# insert method
vowel = ['a', 'e', 'i', 'u']

# 'o' is inserted at index 3 (4th position)
vowel.insert(3, 'o')

print('List:', vowel)

##############


animals = ['cat', 'dog', 'guinea pig', 'dog']
animals.remove('dog')

print('Updated animals list: ', animals)

# error
#animals.remove('fish')

# Updated animals List
print('Updated animals list: ', animals)

# pop
languages = ['Python', 'Java', 'C++', 'French', 'C']

return_value = languages.pop(3)

print('Return Value:', return_value)

print('Updated List:', languages)

languages.pop()
print(languages)

# del

my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]

# deleting the third item
del my_list[2]

# Output: [1, 2, 4, 5, 6, 7, 8, 9]
print(my_list)

# deleting items from 2nd to 4th
del my_list[1:4]

# Output: [1, 6, 7, 8, 9]
print(my_list)

# deleting all elements
del my_list[:]

# Output: []
print(my_list)

prime_numbers = [2, 3, 5, 7, 9, 11]

# remove all elements
prime_numbers.clear()

# Updated prime_numbers List
print('List after clear():', prime_numbers)


# Output: List after clear(): []

##############

# create a list
numbers = [2, 3, 5, 2, 11, 2, 7]

count = numbers.count(2)

print('Count of 2:', count)

prime_numbers = [2, 3, 5, 7]

prime_numbers.reverse()

print('Reversed List:', prime_numbers)

prime_numbers = [11, 3, 7, 5, 2]

# sorting the list in ascending order
prime_numbers.sort()

print(prime_numbers)

vowels = ['e', 'a', 'u', 'o', 'i']

vowels.sort(reverse=True)
print('Sorted list (in Descending):', vowels)

#########

# https://www.programiz.com/python-programming/examples/list-slicing

Lst = [50, 70, 30, 20, 90, 10, 50]

# Display list
print(Lst[1:5]) # from index 1 till index 4

# Initialize list
List = [1, 2, 3, 4, 5, 6, 7, 8, 9]

# Show original list
print("\nOriginal List:\n", List)

print("\nSliced Lists: ")

# Display sliced list
print(List[3:9:2])

# Display sliced list
print(List[::2])

print(List[::])

# String slicing
String = 'CodingIsFun'

# Using indexing sequence
print(String[1:5])


#########


# input values to list
list1 = [12, 3, 4, 15, 20]

for elem in list1:
print(elem)

list1.sort()

print(list1)

colors = ["Red", "Black", "Pink", "White"]

colors.append("Blue") # add --> insert
colors.append("Orange")

for color in colors:
print(color)


print(len(colors))

for i in range(len(colors)):
print(colors[i])

if "Grey" in colors:
print("Yes, present")


list2 = []

list2.append("Abc");

print(list2)

#######







162 changes: 162 additions & 0 deletions concepts/strings_samples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# This file contains all the samples for strings related usecase


# partition the string
# the below returns a tuple with "best" " " "technical interview prep course"

input_words = "best technical interview prep course"
print(input_words.partition(" "))
##############################################################

str = "abcdac"

substr = "xda"

print(str.find(substr)) #



# .join() with lists
numList = ['1', '2', '3', '4']

print(' | '.join(numList)) # "1 | 2 | 3, 4"


cars = "BMW-Telsa-Range Rover"

# split at '-'
print(cars.split("-"))


words = "cats dogs lions"
print(words.split())

#################
# https://www.programiz.com/python-programming/methods/string
# https://www.programiz.com/python-programming/methods/string/split

text = 'bat ball'

print(len(text))

# replace 'ba' with 'ro'
replaced_text = text.replace('ba', 'ro')
print(replaced_text)

song = 'Let it be, let it be, let it be, let it be'

# replacing only two occurrences of 'let'
print(song.replace('let', "don't let", 2))

message = 'python is popular programming language'

# number of occurrence of 'p'
print('Number of occurrence of p:', message.count('p'))

# Output: Number of occurrence of p: 4

quote = 'Let it be, let it be, let it be'

# first occurance of 'let it'(case sensitive)
result = quote.find('let it')
print("Substring 'let it':", result)

# find returns -1 if substring not found
result = quote.find('small')
print("Substring 'small ':", result)

# How to use find()
if (quote.find('be,') != -1):
print("Contains substring 'be,'")
else:
print("Doesn't contain substring")



quote = 'Do small things with great love'

# Substring is searched in 'hings with great love'
print(quote.find('small things', 10))

# Substring is searched in ' small things with great love'
print(quote.find('small things', 2))

# Substring is searched in 'hings with great lov'
print(quote.find('o small ', 10, -1))

# Substring is searched in 'll things with'
print(quote.find('things ', 6, 20))

####

# .join() with lists
numList = ['1', '2', '3', '4']
separator = ', '
print(' | '.join(numList)) # "1 | 2 | 3, 4"

# .join() with tuples
numTuple = ('1', '2', '3', '4')
print(separator.join(numTuple))

s1 = 'abc'
s2 = '123'

# each element of s2 is separated by s1
# '1'+ 'abc'+ '2'+ 'abc'+ '3'
print('s1.join(s2):', s1.join(s2))

# each element of s1 is separated by s2
# 'a'+ '123'+ 'b'+ '123'+ 'b'
print('s2.join(s1):', s2.join(s1))

# first string
firstString = "PYTHON IS AWESOME!"

# second string
secondString = "PyThOn Is AwEsOmE!"

if(firstString.lower() == secondString.lower()):
print("The strings are same.")
else:
print("The strings are not same.")

sentence = "i love PYTHON"

# converts first character to uppercase and others to lowercase
capitalized_string = sentence.capitalize()

print(capitalized_string)

# Output: I love python


message = 'Python is fun'

print(message.startswith('Python'))


#######

message = 'Python is fun'

print(message.startswith('Python'))

cars = 'BMW-Telsa-Range Rover'

# split at '-'
print(cars.split('-'))

text= 'Love thy neighbor'

# splits at space
print(text.split())

grocery = 'Milk, Chicken, Bread'

# splits at ','
print(grocery.split(', '))

# Splits at ':'
print(grocery.split(':'))

######
1 change: 1 addition & 0 deletions helloworld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("hello world")
Loading

0 comments on commit 1282b9a

Please sign in to comment.