def words_to_marks(s): word_list = list(s) a_z = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x','y', 'z'] sum = 0 for w in word_list: sum += a_z.index(w) + 1 return sum

As you might guess, the above is just another question from CodeWars.

Dear readers, I am working hard to build this website just for Python from now onward, if you like this post, do share the post on any social media site, thank you.

Leave your comment or provide your own solution below this post.

]]>In the below example, you need to decide which phrase to return from the array list which consists of good ideas ‘good’ and bad ideas ‘bad’. If there are one or two good ideas, return ‘Publish!’, if there are more than 2 return ‘I smell a series!’. If there are no good ideas, as is often the case, return ‘Fail!’.

def well(x): if x.count('good') > 2: return 'I smell a series!' elif x.count('good') > 0: return 'Publish!' else: return 'Fail!'

Write down your own python answer in below comment box.

If you like this post do share the post on any social media site to help this site to grow, thank you.

]]>E.g. If we have an array [1,2,3,4,6,7,8] then 1 then 2 then 3 then 4 are all consecutive but 6 is not, so that’s the first non-consecutive number.

If the whole array is consecutive then return None.

The array will always have at least 2 elements1 and all elements will be numbered. The numbers will also all be unique and in ascending order. The numbers could be positive or negative and the first non-consecutive could be either too!

Solution :

Take out the first number in the array, then continue to add one to that number, if one of the summation outcomes is not the same as the next number in the array then the program will return that next number or else the program will return None if no non-consecutive number has been found.

def first_non_consecutive(arr): seed = arr.pop(0) for num in arr: seed += 1 if num != seed: return num return None

Any thoughts about the above solution? Please comment below.

If you like any post on this website, please share on social media to help this site gets more readers!

]]>def odd_one(arr): for number in arr: if number % 2 != 0: return arr.index(number) return -1

The method above will loop through the number list to determine the position of the only odd number within that number list. If no odd number has been found then the method above will return -1!

That is a simple solution, if you have better idea then leave your comment below.

**Announcement:**

After a while of rest, I have begun to write again, I am planning to turn this website into a full tech website which will deal with programming, electronic gadget topic, and gaming. Feel free to subscribe to any

For example,

maxGap ({-7,-42,-809,-14,-12}) ==> return (767)

Explanation:

The Maximum Gap after sorting the array is 767, The difference between | -809- (-42) | = 767.

def max_gap(numbers): numbers.sort() gap = [] while(len(numbers) > 1): first = numbers.pop(0) second = numbers[0] gap.append(abs(second-first)) return max(gap)

- Sort the list in ascending order.
- Create a full gap list in the while loop.
- Return the maximum different.

The above question is from Codewars, which is the best website for you to train your Python and other programming skill.

]]>The referee will shout out the score, you have already set up the voice recognition module which turns the ref’s voice into a string, but the spoken score needs to be converted into a pair for the scoreboard!

e.g. “The score is four nil” should return [4,0]

Either teams score has a range of 0-9, and the ref won’t say the same string every time e.g.

“new score: two three”

“two two”

“Arsenal just conceded another goal, two nil”

Create a function which will return the array of scores.

def scoreboard(string): score = ['nil', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] score_arr = [] string_list = string.split(' ') for word in string_list: if word in score: score_arr.append(score.index(word)) return score_arr

These are the steps to create the score array.

- Split the string into a list.
- Iterate through the list.
- Find the scores and append them to the array then return.

For example, capitalize(“abcdef”) = [‘AbCdEf’, ‘aBcDeF’]!

The input will be a lowercase string with no spaces.

def capitalize(s): s = list(s) li = [] stri = '' n = 1 first = False time = 0 while(time < 2): if first == False: for e in s: if n % 2 != 0: stri += e.upper() else: stri += e n+=1 first = True n = 1 li.append(stri) stri = '' time += 1 else: for e in s: if n % 2 == 0: stri += e.upper() else: stri += e n+=1 li.append(stri) time += 1 return li

Do you know we actually can achieve the above outcome with just 3 lines of code? Provide your answer in the comment box below!

]]>def multiples(m, n): arr = [] for number in range(1, m+1): arr.append(n * number) return arr

As you can see, the m parameter has been used in the range method to create the multiplied numbers list.

Your Homework :

Create a method which will only return the multiplied numbers that are not larger than the power of m for the given n number. Provide your answer in the tweet below.

Create a method which will only return the multiplied numbers that are not larger than the power of m for the given n number. Given multiples(m, n) #Python Provide answer below this tweet!

— TechLikin (@ChooWhei) September 1, 2019

If you are serious about learning Python, then homework is the best method to improve your Python skill!

]]>- Extract unique characters from two strings then group them into two separate lists.
- Create a new list consists of the characters in those two lists. The character within the list must only appear once and only consists of lowercase a-z characters.

Below is the solution.

- Create two lists with non-repeated characters from the given two strings.
- Loop through all the lowercase characters (from a-z) and if this character appears within any of those two lists then appends them to a new character list.
- Turn that new list into a string and then returns that new string.

import string def longest(s1, s2): s1 = list(set(s1)) s2 = list(set(s2)) s3 = [] for character in string.ascii_lowercase: if character in s1 or character in s2: s3.append(character) return ''.join(s3)

We will use the string module ascii_lowercase list property to save all the typing we need in order to create the lowercase letters list.

Homework :

Create a new string which only consists of non-repeated digits in the ascending order from two given strings. For example, s1 = “agy569” and s2 = “gyou5370” will produce s3 = “035679”. Write your solution in the comment box below this article.

Do you finish the homework all by your own?

]]>These are the steps we need to do.

- Turn the string into a list of words.
- Create a string which only consists of digits separated by empty space that replaces the words within the digits.
- Create a new list only consists of digits then returns the maximum digit.

def solve(s): s_list = list(s) str = '' for e in s_list: if e.isdigit(): str += e else: str += ' ' n_list = str.split(' ') e_list = [] for x in n_list: if x.isdigit(): e_list.append(int(x)) return max(e_list)

The max method will return the maximum digit within a list.

]]>