Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8f499db

Browse files
Merge pull request #12 from nehalgupta8501/nehal-gupta_4
Adding a Snippet
2 parents e079ca1 + 273eccb commit 8f499db

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

‎README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,46 @@ def get_vowels(string):
376376
get_vowels('foobar') # ['o', 'o', 'a']
377377
get_vowels('gym') # []
378378
```
379+
380+
### Length of Last Word in a string
381+
This method gets the length of last word in a given string.
382+
```
383+
def lengthOfLastWord(self, s: str) -> int:
384+
if(s.split()):
385+
lst=s.split()
386+
last=lst[-1]
387+
return len(last)
388+
return 0
389+
```
390+
### Valid Palindrome
391+
This method returns a bool value specifying whether a string is palindromic or not.
392+
```
393+
def isPalindrome(self, s: str) -> bool:
394+
s = [ x.lower() for x in s if x.isalnum() ]
395+
return s == s[::-1]
396+
```
397+
### Check Lowercase
398+
This method checks if a string is in lower case or not.
399+
```
400+
def toLowerCase(self, str):
401+
"""
402+
:type str: str
403+
:rtype: str
404+
"""
405+
return str.lower()
406+
```
407+
### Count Negatives in a sorted Matrix
408+
This method returns the count of negative numbers in a sorted matrix.
409+
```
410+
def countNegatives(self, grid: List[List[int]]) -> int:
411+
count = 0
412+
for num in grid:
413+
for n in num:
414+
if n < 0:
415+
count += 1
416+
return count
417+
```
418+
379419
### Write to file
380420
This method takes in the ``name of file`` and ``content`` then write the content into the file. If the file doesn't exist then it creates the file.
381421
```python

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /