technical_guru's blog

By technical_guru, 11 months ago, In English,

Let's assume, you have a seq. of strings such as,

# List of string 
list_of_strings = ['Sonia' , 'limo', 'karl', 'jhon', 'john', 'shawn']

Now, we'll check if the input list contains a string element 'john'.

Check if the list has the element — using python IN Operator

# check if the list has the element using 'in'
if 'john' in list_of_strings :
    print("Yes, 'john' found in List:", list_of_strings)

if 'walter' not in list_of_strings :
    print("Yes, 'walter' NOT found in List: " , list_of_strings)

Check if the list has the element — using list.count()

# check if the list has the element using list.count()
if list_of_strings.count('john') > 0 :
    print("Yes, 'john' found in List : " , list_of_strings)

Check if the list has the element — using list comprehension

# check if the list has the element using list comprehension
res = [x for x in list_of_strings if x == 'john']
if res:
   print("Yes, '{}' found in List: {}".format(res[0], list_of_strings))

Ref:- 1) What is a list in Python 2) Python list comprehension

Read more »

 
 
 
 
  • Vote: I like it
  • -19
  • Vote: I do not like it

By technical_guru, history, 18 months ago, In English,

Python is one of the most developer-friendly languages and also is the programming language of the year 2018 as ranked by the TIOBE Index. There are immense growth and development opportunities for professional skilled in Python.

Numerous working domains like Data analytics, machine learning, web scraping, IoT, system automation, test automation are flooded with open positions for deserving candidates. Hence, one needs to learn the language from depth and breadth.

Here are few of the simple and best online tutorials for learning Python.

  1. Python tutorial to learn step by step
  2. Pythonspot
  3. Pythonguru
  4. ProgramizPython

Happy Python learning in 2019.

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it