0% found this document useful (0 votes)
14 views

Python Program Practice 1

Uploaded by

yusuf01asif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Python Program Practice 1

Uploaded by

yusuf01asif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

5/3/2018 Let's Do Together - Session 1

In [1]:

# Install Related
# 1. Install both Python 2.7 and 3.7 from conda environment
# 2. Install advanced libraries through conda environment

In [2]:

#Write a Python program to sum all the items in a list.

In [3]:

#solution
def sum_list(items):
sum_numbers = 0
for x in items:
sum_numbers += x
return sum_numbers
print(sum_list([1,2,-8]))

-5

In [7]:

# Write a Python program to count the number of strings where the string length is 2 or

# more and the first and last character are same from a given list of strings.

In [8]:

#solution
def match_words(words):
ctr = 0

for word in words:


if len(word) > 1 and word[0] == word[-1]:
ctr += 1
return ctr

In [9]:

a=['abc', 'xyz', 'aba', '1221','bhgsskknb','aa']

In [10]:

match_words(a)

Out[10]:

In [11]:

#Write a Python program to remove duplicates from a list.

http://localhost:8888/nbconvert/html/Desktop/IPYNB_Files/10th%20April_Let's%20do%20Together/Let's%20Do%20Together%20-%20Session%201.ipynb?down
5/3/2018 Let's Do Together - Session 1

In [20]:

#Solution
samp_list = [10, 20, 30, 20, 10, 50, 60, 40, 80, 50, 40]
dup_items = set()
uniq_items = []
for x in a:
if x not in dup_items:
uniq_items.append(x)
dup_items.add(x)

print(dup_items)

{40, 10, 80, 50, 20, 60, 30}

In [ ]:

http://localhost:8888/nbconvert/html/Desktop/IPYNB_Files/10th%20April_Let's%20do%20Together/Let's%20Do%20Together%20-%20Session%201.ipynb?down

You might also like