美文网首页
面试真题

面试真题

作者: Ugfly | 来源:发表于2018-02-14 00:43 被阅读0次
    """ 1 :对列表去重,并且保持原来顺序。"""
    # l = [1,2,3,4,4,3,2,1,34,4,5,6,54,4,6,7,67,878,6,567,45,64,345]
    # # ls = set(l)
    # # print(ls)# {64, 1, 2, 3, 4, 34, 5, 6, 7, 67, 45, 878, 54, 567, 345}
    # # ll = list(ls)
    # # ll.sort(key=l.index)
    # # print(ll)
    # ls = list(set(l))
    # ls.sort(key=l.index)
    # print(ls)
    """ 2. 现有两元组(('a'),('b')),(('c'),('d'))。请使用python中匿名函数生成列表[{'a':'c'},{'b':'d'}]"""
    # t = (('a'),('b')),(('c'),('d'))
    # d = {}
    # for i in t :
    #     print(i)
    #     d[i[0]] = i[1]
    #     print(d)
        # ('a', 'b')
        # {'a': 'b'}
        # ('c', 'd')
        # {'a': 'b', 'c': 'd'}
    """ 3. 请给出二分查找的python示例代码。"""
    # def search(num,l,start=None,end=None):
    #     start = start if start else 0
    #     end = end if end else len(l) - 1
    #     mid = (end - start)//2 + start
    #     if start > end:
    #         return None
    #     elif l[mid] > num :
    #         return search(num,l,start,mid-1)
    #     elif l[mid] < num:
    #         return search(num,l,mid+1,end)
    #     elif l[mid] == num:
    #         return mid
    # l = [1,2,3,4,4,3,2,1,34,4,5,6,54,4,6,7,67,878,6,567,45,64,345]
    # num = 878
    # print(search(num,l)) # 17
    
    ''' 4. 在python字符串格式化中,%和.format的主要区别是什么?'''
    
    # %s普通版字符串格式化,还有%d 是十进制数。
    # .format是格式化字符串。 可以按照顺序传入值,也可以根据关键字传值。
    
    ''' 5. *args 和 kwargs 在上面情况下会使用到?给出使用**kwargs的示例代码。'''
    
    
    # x= ' f'
    # y=2
    # # print(x*y)
    #
    # d= {'1':5,'2':22}
    # dd = d
    # d['1'] = 10
    # print(dd)
    # ddd = d['1']+dd['1']
    # print(ddd)
    
    
    # l = [1,2,3,4,5]
    # l1=l[:]
    # l.append(6)
    # print(l1)  # [1, 2, 3, 4, 5]
    
    
    # name1 = [1,2,3,4,5]
    # name2 = name1
    # name3 = name1[:]
    # name2[0] = 'a'
    # name3[1] = 'b'
    # sum = 0
    # for i in (name1,name2,name3):
    #     if i[0] == 'a':
    #         sum += 1
    #     if i[1] == 'b':
    #         sum += 10
    # print(sum)
    # 12
    
    
    # a = lambda p:p*2
    # b = lambda p:p*3
    # x = 2
    # x = a(x)  # 4
    # x = b(x)  # 12
    # x = a(x)  # 24
    # print(x)
    
    
    
    # x = 1
    # y = 0
    # z = 0
    # if x or y and z:
    #     print('6666')
    # else:
    #     print('false')
    # and优先级高
    
    # 在python里面如何实现tuple和list的切换
    # t = (1,2,3,4)
    # print(t,type(t))
    # l = list(t)
    # print(l,type(l))
    # (1, 2, 3, 4) <class 'tuple'>
    # [1, 2, 3, 4] <class 'list'>
    
    # 请用python代码实现删除一个列表里面的重复元素
    # l = [1,2,3,4,5,6,4,3,2,1,6]
    # # ll = []
    # # for i in l :
    # #     if not i in ll :
    # #         ll.append(i)
    # # print(i)
    # ll = list(set(l))
    # ll.sort(key=l.index)
    # print(ll)
    
    
    # 如何得到一个list的交集或者差集
    # l = [1,2,3,4,5]
    # l1 = [1,2,3,4,6,7]
    # # 转为set类型,
    # # >> x & y  # 交集
    # # >> > x | y  # 并集
    # # >> > x - y  # 差集
    # s = set(l)
    # s1 = set(l1)
    # print(list(s&s1))
    # print(list(s-s1))
    # print(list(s|s1))
    
    
    
    # 第三页!!!!!!!!!!!!!!!!!!!!
    
    
    # 产生数组对象
    # 将时间字符串转化为时间对象
    # import datetime
    # date = datetime.datetime.strptime('2018-1-11','%Y-%m-%d')
    # # print(date) # 2018-01-11 00:00:00
    #
    # # 灵活处理时间对象。
    # # import dateutil
    # # date = dateutil.parser.parse('2018-2-2')
    # # print(date)
    #
    import pandas  # 你知道开始和结尾就可以知道中间的日子,可以自动识别闰年。
    # # print(pandas.date_range('2015-12-1','2016-2-2'))
    # # print(pandas.date_range('2016-1-1',periods=40,freq='B')) # periods 时间 长度  第三个参数默认D
    # """
    # start     开始时间
    # end       结束时间
    # periods       时间长度
    # freq      时间频率,默认为'D',可选H(our),W(eek),B(usiness),S(emi-)M(onth),(min)T(es), S(econd), A(year),…
    # """
    #
    # # #####文件操作
    # df = pandas.read_csv('') # 逗号分隔
    # df1 = pandas.read_csv('',sep='\s+') # 逗号分隔
    # df2 = pandas.read_table('',) # \t 分隔 制表符
    
    
    import matplotlib.pyplot as plt
    import numpy as np
    
    # plt.plot([0,1,2,3],[4,7,9,13],marker=',')
    # plt.plot([2,3,32,3,31])
    # plt.title = ('pipipi')
    # plt.show()
    
    # x = np.linspace(-100,100,100000)  # start end  切成多少块
    # y1 = x
    # plt.plot(x,y1,label='$y=x')  # 加了$,就是公式环境。
    # plt.legend()
    
    
    plt.pie([1,2,3],labels=['a','b','c'])
    plt.axis('equal')
    # plt.show()
    
    
    
    
    import socket
    # s = socket.gethostbyname('baidu.com')
    # print(s)
    

    相关文章

      网友评论

          本文标题:面试真题

          本文链接:https://www.haomeiwen.com/subject/dabstftx.html