老师,既然equals相同的对象,hashcode也相同,不同的对象hashcode也不同。那源码中为什么不把hashcode储存起来,直接比较hashcode就行了呀,为什么还要费力的去比较对象的内容呢?
老师,这里主键约束特点应该是非空,而不是为空吧
def dictionary_reader(filename): """ :param filename: The type of the filename is string, which means users need to input a string type's filename. :return: a list which contain each word in the file """ words_no_punctuation = [] words_less_than_9 = [] try: # open the file and execute the read operation f = open(filename, 'r') # append the each word speratly into a list words = f.readlines() for word in words: words_no_punctuation.append(word.strip()) for word in words_no_punctuation: if len(word) <= 9: words_less_than_9.append(word) # print(len(words_less_than_9)) # This is the test part of the dictionary_reader # Test passd, if length of list equal to 235887 x = '' for word in words_less_than_9: if len(word) > 9: x = False break else: x = True continue if x == False: print("Not all of the len of word in this list, which is less than 9 characters.") else: print("-----Test passed! All words in this list are less than 9 characters-----") if len(words) == 235887: print("-----Test passed! There are 235887 words in the list!-----") else: print("The len of words is not equal to the len of word in the words.txt.") if isinstance(words_less_than_9, list): print("-----Test pssed! The function dictionary_reader will return the all words which len are less than 9 characters in a list!-----") else: print("The return stuff is not the list type.") return words_less_than_9 except BaseException as e: # print the error information when programme meet error # it is easy to help users matain the programme print(e) finally: # make sure the file stream will be closed in any suitation of programme f.close() def word_lookup(): # read file at first # words is a list, and each elements in the words list is a word. words = dictionary_reader('words.txt') sorted_dictionary = [] longest_words = [] possibility_words = [] for word in words: """ every single word in the words list will be sorted by alphabetical. """ word = word.strip() # ensure every single word in the list is lowercase sorted_dictionary.append("".join(sorted(word)).lower()) print(sorted_dictionary)
words.txt WechatIMG945.png
老师您好,这是我写的的两个函数。在word_lookup里面我尝试把文件里面的每一个单子都变成字母排序,但是控制台输出的第一个单词并不是按字母排序去排序的,请问一下这是为什么?
输出在附件里面传上去了,不知道为什么不能够上传图片,抱歉。
谢谢老师
老师,我记得课程前面好像没有讲过freemarker...这次突然用Spring整合,看得我有点懵,虽说这个整合的操作上跟jsp没太大区别
老师,请问一下,这部分代码中的子线程为什么没有跟主线程抢占资源,每次都是主线程中的循环结束,才进行子线程的输出的
再看下面的一份代码
这个运行结果,子线程还会跟主线程抢占资源
这两种代码有什么出入吗
请您帮忙解答一下,谢谢
老师,您看一下,我写的,我收不到消息
from socket import * # 发信息 s = socket(AF_INET,SOCK_DGRAM) s.bind(('', 8788)) s.sendto(b"aaabbbccc", ("112.10.81.85", 8099)) redate = s.recvfrom(1024) print(redate[0].decode()) """收信息程序""" from socket import * udpSock = socket(AF_INET, SOCK_DGRAM) udpSock.bind(("", 8099)) while True: recvDate = udpSock.recvfrom(1024) print(recvDate[0].decode()) udpSock.sendto(recvDate[0], recvDate[1]) udpSock.close()
老师,您看一下,我的IP地址,是我百度搜索的
requests re fake_useragent UserAgent url=resp=requests.get(url,={:UserAgent().random}) resp.encoding=html=resp.text (html) contens=re.findall(,html) temp contens: (contens)
老师我想请问这个代码怎么爬取 怎么爬它都会自动去匹配更后面的img很无奈
老师,这里department作为主表并且department_id也建立了索引,但是最终还是全表扫描,是不是系统优化器认为这里的情况是全表扫描性能更高一些,而不一定非得扫描索引?
被protected修饰的类,方法,变量,可以在本包中使用,或者可以在其的子类中使用,这里遇到了这个问题,在其
子类中调用被protected修饰的变量,却报错了,请看一下
父类:
package cn.sxt.demo; public class TestEncapsulationUser { private String name; public int age; String address; protected double salary; public static void main(String[] args) { System.out.println(new TestEncapsulationUser().name);//private 修饰的只能在本类中使用 } } class User { private static TestEncapsulationUser testu; public User() { testu = new TestEncapsulationUser(); } public static void main(String[] args) { // System.out.println(testu.name);//不同类无法直接调用被访问修饰符private修饰过的变量,方法,类 System.out.println(testu.age);//public 修饰的不同类中可见 System.out.println(testu.salary);//protected修饰的同一个包中可见 } }
子类:
问题:并没有删除cc的父目录bb,没找到原因?
package com.bjsxt.File; import java.io.File; public class testDirectory { public static void main(String[] args) { // File f = new File("/Users/hongjuansun/Desktop/testDirectory"); // f.mkdir();//创建单层目录 // System.out.println("判断目录是否存在:"+f.exists()); // System.out.println("是否是目录:"+f.isDirectory()); // System.out.println("删除目录:"+f.delete()); //delete删除目录时,只能删除空目录 File f1 = new File("/Users/hongjuansun/Desktop/aa/bb/cc");//虽然创建了3个目录,但是f1代表的是cc f1.mkdirs();//创建多层目录 File parent = f1.getParentFile();//获取cc目录的父级目录 System.out.println("cc的父目录是:"+parent); //此时我想删除cc的父目录,但是delete删除目录时只能删除空目录,所以先删除cc,在删除cc的父目录 f1.delete();//删除cc System.out.println(parent.delete());//打印是否删除bb目录 } }
程序运行结果:
桌面查看文件夹结果:
老师,您好请问程序员修炼手册有没有电子版的?
老师好:
这里在重写了equals()方法后,同一类的相同属性值的对象才会返回true, 如果不重写equals()方法,也可以比较,不过就是结果是false,想问一下,不重写equal()方法,比较的是什么。
老师,你给我发过来一份生产者整合Spring框架的源代码来吧,我试一试
老师,能否告知 Idea 的SpringBoot项目怎么访问webapp下的资源,我百度了好多方法,将webapp设置成web模块,以及web.xml相关文件放进去了依然访问不了图片,请老师教我一下,提前感谢老师。
报错误,生产者一直报错,消费者对的了,不知道为什么,百度了也不行
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637