Python assignment 1.py - # -*- coding: utf-8 -*" Spyder...

This preview shows page 1 - 2 out of 4 pages.

The preview shows page 1 - 2 out of 4 pages.
# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file."""#1. create 2 list consist of interger, float, strings, complex, booleana=[1,2.1,"You are young", "2+3j","True","False"]b=[1,3.1,"You are smart","3+3j","True","False"]#a. Create another list by concatenating 2 list togethera+b#b.Find the frequency of each element in the concatenated list.#frequency of 1#Method 1:using loopmylist=[1,2.1,"You are young", "2+3j","True","False",1,3.1,"You aresmart","3+3j","True","False"]x=1count=0for ele in mylist:if(ele==x):count=count+1print("{} has occured {} times".format(x,count))#Frequency of 2.1#method 2:using count ()mylist=[1,2.1,"You are young", "2+3j","True","False",1,3.1,"You aresmart","3+3j","True","False"]x=2.1print("{} has occured {} times".format(x,mylist.count(x)))# frequency of "You are young"mylist=[1,2.1,"You are young", "2+3j","True","False",1,3.1,"You aresmart","3+3j","True","False"]x="You are young"count=0for ele in mylist:if(ele==x):count=count+1print("{} has occured {} times".format(x,count))#frequency of "2+3j"mylist=[1,2.1,"You are young", "2+3j","True","False",1,3.1,"You aresmart","3+3j","True","False"]x="2+3j"

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 4 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
professor_unknown
Tags
Chemical element, The Elements

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture