Python checkio "Friends"解决方案
来源:互联网 发布:网络电视直播播放器 编辑:程序博客网 时间:2024/06/05 16:14
class Friends: def __init__(self, connections): self.connectlist = list(connections) def add(self, connection): b = False if connection in self.connectlist else self.connectlist.append(connection) return b is not False def remove(self, connection): b = self.connectlist.remove(connection) if connection in self.connectlist else False return b is not False def names(self): return set(name for pair in self.connectlist for name in pair) def connected(self, name): c =set() [c.update(connect.difference(name)) for connect in self.connectlist if name in connect] if name in c :c.remove(name) return set() if len(c) == 0 else cclass Friends1: def __init__(self, connections): self.connections = [] for i in connections: self.add((i)) def add(self, connection): if sorted(connection) in self.connections: return False else: self.connections.append(sorted(connection)) return True def remove(self, connection): if sorted(connection) in self.connections: self.connections.pop(self.connections.index(sorted(connection))) return True else: return False def names(self): names_set = set() for i in self.connections: names_set.add(i[0]) names_set.add(i[1]) return names_set def connected(self, name): names = set() for i in self.names(): if sorted([name, i]) in self.connections: names.add(i) return namesclass Friends2: def __init__(self, connections): self.connections = list(connections) def add(self, connection): if connection in self.connections: return False self.connections.append(connection) return True def remove(self, connection): if not connection in self.connections: return False self.connections.remove(connection) return True def names(self): return set(name for pair in self.connections for name in pair) def connected(self, name): return set(tuple({name} ^ pair)[0] for pair in self.connections if name in pair)
阅读全文
0 0
- Python checkio "Friends"解决方案
- Python checkio median解决方案
- Checkio--Friends
- Python checkio Monkey Typing解决方案
- Python checkio Pawn Brotherhood解决方案
- Python checkio Long Repeat解决方案
- Python checkio First Word解决方案
- Python checkio Secret Message解决方案
- Python checkio Index Power解决方案
- Python checkio Digits Multiplication解决方案
- Python checkio Days Between解决方案
- Python checkio Cipher map解决方案
- Python checkio Boolean Algebra解决方案
- Python checkio "Ghosts age"解决方案
- Python checkio "Striped Words"解决方案
- Python checkio "Speech Module"解决方案
- Python checkio "Making Change"解决方案
- Python checkio "Building Base"解决方案
- axios 以POST方式提交数据springMVC @RequestParam无法接受
- find查找与删除
- php 将多个文件压缩成zip并下载到本地
- Cocoa设计模式(iOS常用设计模式) Cocoa Design Patterns
- 设计一个动物声音“模拟器”,希望通过模拟器可以模拟许多动物的叫声
- Python checkio "Friends"解决方案
- JS 控制 audio 标签 播放/暂停 音乐
- 数据结构实验之查找四:二分查找
- 图像目标检测与跟踪学习笔记(五)
- AngularJS简介
- 《JAVA与模式》之责任链模式
- 手把手教你开发chrome扩展一:开发Chrome Extenstion其实很简单
- python3 异常处理
- Angular 4.3 HttpClient (Angular访问 REST Web 服务) 一、Http 请求示例(Get)