Skip to content

Commit

Permalink
correction and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Asabeneh committed Jul 8, 2023
1 parent 623a552 commit b78270f
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Python Variable Name Rules
- A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and \_ )
- Variable names are case-sensitive (firstname, Firstname, FirstName and FIRSTNAME) are different variables)

Let us se valid variable names
Here are some example of valid variable names:

```shell
firstname
Expand Down
16 changes: 8 additions & 8 deletions 04_Day_Strings/04_strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ Now, let us see the use of the above escape sequences with examples.
```py
print('I hope everyone is enjoying the Python Challenge.\nAre you ?') # line break
print('Days\tTopics\tExercises') # adding tab space or 4 spaces
print('Day 1\t3\t5')
print('Day 2\t3\t5')
print('Day 3\t3\t5')
print('Day 4\t3\t5')
print('Day 1\t5\t5')
print('Day 2\t6\t20')
print('Day 3\t5\t23')
print('Day 4\t1\t35')
print('This is a backslash symbol (\\)') # To write a backslash
print('In every programming language it starts with \"Hello, World!\"') # to write a double quote inside a single quote

Expand Down Expand Up @@ -328,16 +328,16 @@ print(challenge.expandtabs(10)) # 'thirty days of python'

```py
challenge = 'thirty days of python'
print(challenge.find('y')) # 16
print(challenge.find('th')) # 17
print(challenge.find('y')) # 5
print(challenge.find('th')) # 0
```

- rfind(): Returns the index of the last occurrence of a substring, if not found returns -1

```py
challenge = 'thirty days of python'
print(challenge.rfind('y')) # 5
print(challenge.rfind('th')) # 1
print(challenge.rfind('y')) # 16
print(challenge.rfind('th')) # 17
```

- format(): formats string into a nicer output
Expand Down
4 changes: 2 additions & 2 deletions 05_Day_Lists/05_lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ print(second_last) # mango
### Unpacking List Items

```py
lst = ['item','item2','item3', 'item4', 'item5']
lst = ['item1','item2','item3', 'item4', 'item5']
first_item, second_item, third_item, *rest = lst
print(first_item) # item1
print(second_item) # item2
Expand All @@ -175,7 +175,7 @@ print(rest) # ['item4', 'item5']
```py
# First Example
fruits = ['banana', 'orange', 'mango', 'lemon','lime','apple']
first_fruit, second_fruit, third_fruit, *rest = lst
first_fruit, second_fruit, third_fruit, *rest = fruits
print(first_fruit) # banana
print(second_fruit) # orange
print(third_fruit) # mango
Expand Down
10 changes: 3 additions & 7 deletions 07_Day_Sets/07_sets.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ Set is a collection of items. Let me take you back to your elementary or high sc

### Creating a Set

We use curly brackets, {} to create a set or the *set()* built-in function.
We use the _set()_ built-in function.

- Creating an empty set

```py
# syntax
st = {}
# or
st = set()
```

Expand All @@ -80,7 +78,7 @@ We use **len()** method to find the length of a set.
```py
# syntax
st = {'item1', 'item2', 'item3', 'item4'}
len(set)
len(st)
```

**Example:**
Expand Down Expand Up @@ -131,7 +129,7 @@ fruits.add('lime')
```

- Add multiple items using _update()_
The *update()* allows to add multiple items to a set. The *update()* takes a list argument.
The _update()_ allows to add multiple items to a set. The _update()_ takes a list argument.

```py
# syntax
Expand Down Expand Up @@ -174,7 +172,6 @@ fruits = {'banana', 'orange', 'mango', 'lemon'}
removed_item = fruits.pop()
```


### Clearing Items in a Set

If we want to clear or empty the set we use _clear_ method.
Expand Down Expand Up @@ -427,7 +424,6 @@ age = [22, 19, 24, 25, 26, 24, 25, 24]
1. Explain the difference between the following data types: string, list, tuple and set
2. _I am a teacher and I love to inspire and teach people._ How many unique words have been used in the sentence? Use the split methods and set to get the unique words.


🎉 CONGRATULATIONS ! 🎉

[<< Day 6](../06_Day_Tuples/06_tuples.md) | [Day 8 >>](../08_Day_Dictionaries/08_dictionaries.md)
1 change: 1 addition & 0 deletions 10_Day_Loops/10_loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ while condition:
count = 0
while count < 5:
if count == 3:
count = count + 1
continue
print(count)
count = count + 1
Expand Down
12 changes: 7 additions & 5 deletions 17_Day_Exception_handling/17_exception_handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
[<< Day 16](../16_Day_Python_date_time/16_python_datetime.md) | [Day 18 >>](../18_Day_Regular_expressions/18_regular_expressions.md)

![30DaysOfPython](../images/[email protected])

- [📘 Day 17](#-day-17)
- [Exception Handling](#exception-handling)
- [Packing and Unpacking Arguments in Python](#packing-and-unpacking-arguments-in-python)
Expand Down Expand Up @@ -128,6 +129,7 @@ I alway run.
```

It is also shorten the above code as follows:

```py
try:
name = input('Enter your name:')
Expand Down Expand Up @@ -223,9 +225,9 @@ print(sum_all(1, 2, 3, 4, 5, 6, 7)) # 28
def packing_person_info(**kwargs):
# check the type of kwargs and it is a dict type
# print(type(kwargs))
# Printing dictionary items
# Printing dictionary items
for key in kwargs:
print("{key} = {kwargs[key]}")
print(f"{key} = {kwargs[key]}")
return kwargs

print(packing_person_info(name="Asabeneh",
Expand All @@ -247,7 +249,7 @@ Like in JavaScript, spreading is possible in Python. Let us check it in an examp
```py
lst_one = [1, 2, 3]
lst_two = [4, 5, 6, 7]
lst = [0, *list_one, *list_two]
lst = [0, *lst_one, *lst_two]
print(lst) # [0, 1, 2, 3, 4, 5, 6, 7]
country_lst_one = ['Finland', 'Sweden', 'Norway']
country_lst_two = ['Denmark', 'Iceland']
Expand All @@ -257,7 +259,7 @@ print(nordic_countries) # ['Finland', 'Sweden', 'Norway', 'Denmark', 'Iceland']

## Enumerate

If we are interested in an index of a list, we use *enumerate* built-in function to get the index of each item in the list.
If we are interested in an index of a list, we use _enumerate_ built-in function to get the index of each item in the list.

```py
for index, item in enumerate([20, 30, 40]):
Expand Down Expand Up @@ -301,4 +303,4 @@ print(fruits_and_veges)

🎉 CONGRATULATIONS ! 🎉

[<< Day 16](../16_Day_Python_date_time/16_python_datetime.md) | [Day 18 >>](../18_Day_Regular_expressions/18_regular_expressions.md)
[<< Day 16](../16_Day_Python_date_time/16_python_datetime.md) | [Day 18 >>](../18_Day_Regular_expressions/18_regular_expressions.md)
83 changes: 43 additions & 40 deletions 18_Day_Regular_expressions/18_regular_expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ import re

To find a pattern we use different set of *re* character sets that allows to search for a match in a string.

* *re.match()*: searches only in the beginning of the first line of the string and returns matched objects if found, else returns None.
* *re.search*: Returns a match object if there is one anywhere in the string, including multiline strings.
* *re.findall*: Returns a list containing all matches
* *re.split*: Takes a string, splits it at the match points, returns a list
* *re.sub*: Replaces one or many matches within a string
- *re.match()*: searches only in the beginning of the first line of the string and returns matched objects if found, else returns None.
- *re.search*: Returns a match object if there is one anywhere in the string, including multiline strings.
- *re.findall*: Returns a list containing all matches
- *re.split*: Takes a string, splits it at the match points, returns a list
- *re.sub*: Replaces one or many matches within a string

#### Match

Expand Down Expand Up @@ -129,7 +129,7 @@ substring = txt[start:end]
print(substring) # first
```

As you can see, search is much better than match because it can look for the pattern throughout the text. Search returns a match object with a first match that was found, otherwise it returns _None_. A much better *re* function is *findall*. This function checks for the pattern through the whole string and returns all the matches as a list.
As you can see, search is much better than match because it can look for the pattern throughout the text. Search returns a match object with a first match that was found, otherwise it returns *None*. A much better *re* function is *findall*. This function checks for the pattern through the whole string and returns all the matches as a list.

#### Searching for All Matches Using *findall*

Expand Down Expand Up @@ -240,38 +240,39 @@ matches = re.findall(regex_pattern, txt)
print(matches) # ['Apple', 'apple']

```

* []: A set of characters
* [a-c] means, a or b or c
* [a-z] means, any letter from a to z
* [A-Z] means, any character from A to Z
* [0-3] means, 0 or 1 or 2 or 3
* [0-9] means any number from 0 to 9
* [A-Za-z0-9] any single character, that is a to z, A to Z or 0 to 9
* \\: uses to escape special characters
* \d means: match where the string contains digits (numbers from 0-9)
* \D means: match where the string does not contain digits
* . : any character except new line character(\n)
* ^: starts with
* r'^substring' eg r'^love', a sentence that starts with a word love
* r'[^abc] means not a, not b, not c.
* $: ends with
* r'substring$' eg r'love$', sentence that ends with a word love
* *: zero or more times
* r'[a]*' means a optional or it can occur many times.
* +: one or more times
* r'[a]+' means at least once (or more)
* ?: zero or one time
* r'[a]?' means zero times or once
* {3}: Exactly 3 characters
* {3,}: At least 3 characters
* {3,8}: 3 to 8 characters
* |: Either or
* r'apple|banana' means either apple or a banana
* (): Capture and group
- [a-c] means, a or b or c
- [a-z] means, any letter from a to z
- [A-Z] means, any character from A to Z
- [0-3] means, 0 or 1 or 2 or 3
- [0-9] means any number from 0 to 9
- [A-Za-z0-9] any single character, that is a to z, A to Z or 0 to 9
- \\: uses to escape special characters
- \d means: match where the string contains digits (numbers from 0-9)
- \D means: match where the string does not contain digits
- . : any character except new line character(\n)
- ^: starts with
- r'^substring' eg r'^love', a sentence that starts with a word love
- r'[^abc] means not a, not b, not c.
- $: ends with
- r'substring$' eg r'love$', sentence that ends with a word love
- *: zero or more times
- r'[a]*' means a optional or it can occur many times.
- +: one or more times
- r'[a]+' means at least once (or more)
- ?: zero or one time
- r'[a]?' means zero times or once
- {3}: Exactly 3 characters
- {3,}: At least 3 characters
- {3,8}: 3 to 8 characters
- |: Either or
- r'apple|banana' means either apple or a banana
- (): Capture and group

![Regular Expression cheat sheet](../images/regex.png)

Let us use examples to clarify the meta characters above
Let us use examples to clarify the meta characters above

### Square Bracket

Expand Down Expand Up @@ -367,7 +368,7 @@ print(matches) # ['6', '2019', '8', '2021']

### Cart ^

* Starts with
- Starts with

```py
txt = 'This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
Expand All @@ -376,7 +377,7 @@ matches = re.findall(regex_pattern, txt)
print(matches) # ['This']
```

* Negation
- Negation

```py
txt = 'This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
Expand All @@ -388,7 +389,9 @@ print(matches) # ['6,', '2019', '8', '2021']
## 💻 Exercises: Day 18

### Exercises: Level 1

1. What is the most frequent word in the following paragraph?

```py
paragraph = 'I love teaching. If you do not love teaching what else can you love. I love Python if you do not love something which can give you all the capabilities to develop an application what else can you love.
```
Expand Down Expand Up @@ -423,9 +426,9 @@ print(matches) # ['6,', '2019', '8', '2021']
2. The position of some particles on the horizontal x-axis are -12, -4, -3 and -1 in the negative direction, 0 at origin, 4 and 8 in the positive direction. Extract these numbers from this whole text and find the distance between the two furthest particles.

```py
points = ['-1', '2', '-4', '-3', '-1', '0', '4', '8']
sorted_points = [-4, -3, -1, -1, 0, 2, 4, 8]
distance = 8 -(-4) # 12
points = ['-12', '-4', '-3', '-1', '0', '4', '8']
sorted_points = [-12, -4, -3, -1, -1, 0, 2, 4, 8]
distance = 8 -(-12) # 20
```

### Exercises: Level 2
Expand Down Expand Up @@ -453,4 +456,4 @@ distance = 8 -(-4) # 12

🎉 CONGRATULATIONS ! 🎉

[<< Day 17](../17_Day_Exception_handling/17_exception_handling.md) | [Day 19>>](../19_Day_File_handling/19_file_handling.md)
[<< Day 17](../17_Day_Exception_handling/17_exception_handling.md) | [Day 19>>](../19_Day_File_handling/19_file_handling.md)
Loading

0 comments on commit b78270f

Please sign in to comment.